Editorial for LETCNT

The problem stats to find the most occurring alphabet and then print alphabetically. So easiest approach is to make a frequency array (count the number of letters occurring in the string)

Then as we are interested in printing the letters we are needed to take care of the indexes. So finding the maximum element from the frequency array we also need to calculate the distance from the beginning for the letter to be printed.

Finally, if there are elements having the same frequency we need to take care of that first occurrence of the letter is only counted as we need to print it alphabetically.

Hope you enjoyed !!

Link to the problem

Link to the code

Just make an array of pair of 26 elements such that (character_frequency,char_no).

For example - (|‘a’|,0), (|‘b’|,1) … (|‘z’|,25)

Treat this as the frequency array. And after completing this frequency array, sort the array with a condition that

if (pair1.first!=pair2.first), then return pair1.first>pair2.first;

else return pair1.second<pair2.second

And then print the required answer. I think, this approach is much better for anyone to understand.