2 test cases not working. Please help where should I make changes

#include
#include
#include"bits/stdc++.h"

using namespace std;

int main()
{

char str[1000];
char ans;
cin>>str;
int count[256];
int max=0;
int l = strlen(str);
for(int i=0;i<l;i++){
	count[str[i]]++;
	if(max<count[str[i]]){
		max = count[str[i]];
		ans = str[i];
	}

}
cout<<ans<<endl;
return 0;

}

hello @Ekansh_14 could you please share your code by saving it on ide.codingblocks.com

I have saved it with the name maxFrequency.cpp

no you have to share your code in the link format.

hello @Ekansh_14 your code was not even printing the correct result for sample test case.
Anyway, i have correcte your code:


the error was you should initilaise your frequency array with 0 .
if you feel that your doubt is cleared, mark this doubt as resolved.
Happy Learning!!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.