String max frequency character

one test case is failing
#include
#include
#include
#include
using namespace std;
int main() {
string s;
cin>>s;
int n=s.size();
sort(s.begin(),s.end());

char ch[1000];
vectora(s.size(),1);
int i;
int k=0;
int l=0;
for(i=0;i<s.size();i++){
if(s[i+1]==s[i]) {
ch[l]=s[i];
a[k]++;
}
else{
k++;

 l++;

}}
k–;
int max=0;
int index=0;
for(i=0;i<k+1;i++){

 if(a[i]>max){
 max=a[i];
 index=i;

}

}

cout<<ch[index];
return 0;
}

Could you please copy your code on ide and then share the link.

https://ide.codingblocks.com/s/51460

Hey Pritika, your code will not work if the string is having only one character. for eg.

input:
b

your code doesn’t print anything but the expected output is:
b

https://ide.codingblocks.com/s/308885 this is my code and this passes all the test case.