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


Please Help Members By Posting Answers For Below Questions

hi viewers, tell me,what is scripting and programming, define and difference...pls

1499


Given an array all of whose elements are positive numbers, find the maximum sum of a subsequence with the constraint that no 2 numbers in the sequence should be adjacent in the array. So 3 2 7 10 should return 13 (sum of 3 and 10) or 3 2 5 10 7 should return 15 (sum of 3, 5 and 7)

753


iam confused among testing ,.net and java. can anybody help me.

1570


Find out the roles which gives access to all tables in SAP? Thanks in advance.

1559


When you deliver your C++ headers and C++ library of a class (what all can you change in the class so that application using your class does not need to recompile the code)

720






What is BASIS

1661


Suppose server object is not loaded into the memory, and the client request for it , what will happen?

2166


EXPLAIN UNARY OPEARATORS

1798


Write a program to create a process in UNIX

2085


how many types of operating system are avaliable?

1810


Write a program to reverse a number?

653


what is the BAM? where we can use it in BizTalk server?

1351


which worker is involved in all the phases of SDLC?

1699


Given an array of size n. It contains numbers in the range 1 to n. Each number is present at least once except for 1 number. Find the missing number

719


I want to pass .pdf files as OlE Object to crystal report through VB6. Please any one guid me...

2591