Count-frequency problem

This is my code can someone correct it please

hi @akshat42bajpai
corrected code -->

can you also tell how do i find the maximum of it…i am not able to do it

hi @akshat42bajpai
i hope its clear now??

i did the same vaibhav yesterday but it wasn’t passing the sample test cases

please reffer the below code to rectify your errors->

#include <bits/stdc++.h>
using namespace std;
// #include
// #include

void MaxCharacter(string &str){

// make a frequency array for all the alphabets

// with index zero

int freq[26] = {0};

// construct character count array from input string

int len = str.length();

int max = 0;

char result; //intitiliaze the result

// traverse through the string for mapping

for(int i=0;i<len;i++){

    freq[str[i]-'a']++;

    if(max<freq[str[i]-'a']){

        max = freq[str[i]-'a'];

        result= str[i];

    }

}

cout<<result;

}

int main() {

string str;

getline(cin, str);

    

MaxCharacter(str);

return 0;

}

hi @akshat42bajpai
the code u sent me, in that what u were doing was computing frequency of all characters and just printing them… u had not written the part to find the max freq character…

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.