A string of charaters were given. Find the highest
occurance of a character and display that character.
eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE
Answer Posted / paindriven
char HighestCharCount(const char* str)
{
const int length = strlen(str);
if (length == 0)
return ' ';
if (length == 1)
return str[0];
int indexOfHighest = int(-1);
int highestCounter = 0;
for (int i=0; i < length; ++i)
{
const int remain = length - i;
char test = str[i];
int current = 0;
for (int j=i+1; j < remain; ++j)
{
if (str[j] == test)
{
current++;
if (current > highestCounter)
{
highestCounter = current;
indexOfHighest = i;
}
}
}
}
return str[indexOfHighest];
}
| Is This Answer Correct ? | 38 Yes | 10 No |
Post New Answer View All Answers
what is the filters in biztakk server? where it can use?
how do you generate source code for the automatic generation for receipt number
In OB52 , How to define two open posting period, Like only 5 and 8 posting should be open.. should not open 6 and 7..period..
Why did you ever become involved in QA/testing?
kindly send interview materials
Which CRM is better to opt, Sebiel CRM or Salesforce CRM or sap CRM? which institute is best one in hyderabad
how many types of operating system are avaliable?
what is an INI file?
how much fee for deccan soft institute .how to block seat for sandeep sir class reply soonnnnÂ
if 3 duplicate records, by keeping one original and one duplicate record, and how to delete remaining 2 duplicates in sql server 2008
Which language they use during interview?
Busy waiting is a method whereas a taskwaits for a given event by continiously checking for an event to occur. What is the main problem with this approach
Write a shell program. Enter number of days from keyboard. Find out the number of years, month and days it contains
the systematic access of small computers in a distributed data processing system is referred as?
what is dot net framework