Check my code please

I have written a code for calculating max freq character of the string

///my Code

#include
using namespace std;
int maxfreq(string str)
{

int n=str.length();
int i=0;
int j=i+1;
int c;
int m=0;
char Max='\0';
while(i!=n-1)
{
    while(j!=n-1)
    {
        int c=0;
        if(str[i]==str[j])
        {
            c++;
            j++;
        }
        else
        {
            j++;
        }
    }
    if(c>m)
    {
        m=c;

    if(m>Max){
        Max=str[i];

    }
    }
    i++;
}
return Max;

}

int main()
{
string str;
cin>>str;
char ch=maxfreq(str);
cout<<ch;
}

/// My code works fine on code blocks but while submitting the test cases are showing wrong . can you help me.

hi @Souryaman this approach is not good as it will take too much time. You can solve this problem in O(n) by using a frequency array.

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.