2 test case fails and also it there is any optimized appraoches
Test case fails
@Vikaspal, in your for loop the condition should be i<n and j<n instead of i<(n-1) and j<(n-1)
corrected code :-
there is indeed a much better solution , since every character has a ascii code that lies in [0,128] range so what you can do is make a frequency array initialized with 0 , which will store the frequency of every character , loop through your string and increment the frequency of index corresponding to the index of ascii character and finally output the max value in frequency array
code :-
@O17LPOLA020023 i donβt understand the loop but freq[str[i]]++ , str[i] will going to return the character let say a then freq[a]++ ??
str[i] is a character and each character has a ascii code which is an integer so ,say str[i] is βaβ then when we do freq[βaβ]++ it will mean freq[97]++ βaβ will be typecasted to its ascii counterpart
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.