my solution passed all test-case but i am thinking of better solution here is my code …
please explain new approach.
thank you …
my solution passed all test-case but i am thinking of better solution here is my code …
please explain new approach.
thank you …
@Diwyanshu,
Just maintain a frequency array of size 26 where index_i represents i_{th} alphabet. Now simply iterate over array ones and increment the frequency of the alphabet encountered. After this the alphabet with max frequency will be the answer.
sorry but i unable to understand the approach can you tell in detail
thank you
@Diwyanshu,
Take a pen and paper, make an array(freq) of size=26 (initialised with 0), take a random string, iterate over it, when you on s[i], increment freq[s[i]-‘a’]++. Afterwards, find which letter has highest frequency.
can you explain this freq[s[i]-‘a’]++ or any reference …
@Diwyanshu,
freq[‘a’-‘a’]= freq[0];
freq[‘b’-‘a’]= freq[1];
freq[‘c’-‘a’]= freq[2];
freq[‘d’-‘a’]= freq[3];
…
freq[‘z’-‘a’]= freq[25];