Microsoft Interview Question
Software Engineer in TestsUsing a hash technique..
int maxcount(string str){
map<char,int> matches;
if(str.size()<=0)
return 0;
int max=1;
for(int i=0;i<str.size();++i){
if(matches.find(str[i]) == matches.end()){
matches.insert(pair<char,int>(str[i],1));
}
else
{
matches.find(str[i])->second++;
if(max<matches.find(str[i])->second)
max=matches.find(str[i])->second;
}
}
return max;
}
Test cases which actually recovered bugs for me
Input- output
aabbaac - 4
abcabc - 2
-0//null string
a- 1
123ab2- 2
^^^cd12- 3
Aabbb- 3
counting sort
- asuran October 14, 2008