This is the desired result which I want:

enter image description here

  • $\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 '21 at 15:40

Just use an array indexed by the characters, loop over the string increasing the respective count.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.