Most frequent character
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
Most frequent character
Return the character that appears most often in a non-empty String. If two characters tie, return the one that appears earliest. A simple approach: for each character, count how many times it occurs, and keep the best so far — using a strict > so a tie keeps the earlier character.
Complete mostFrequentChar(String s) so it returns the most-common character. On a tie, return the one that appears earliest. Assume s is not empty.
Click Run to see the output here.