This is the desired result which I want:
-
$\begingroup$ You could use an associative array in which the keys are the alphabet, in order, and the values start with $0$ and get increased with each new occurrence of the corresponding letter. After the input has been processed, go over the array keeping the position with maximum value so far and only updating if a new position appears with an strictly larger value. $\endgroup$ – plop Feb 27 at 15:40
Just use an array indexed by the characters, loop over the string increasing the respective count.