Skip to content

Most frequent character

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.

Log in or create account

IGCSE & A-Level