#K4446. Most Frequent Character
Most Frequent Character
Most Frequent Character
You are given a string s
consisting of lowercase English letters. Your task is to find the character that appears the most number of times in the string. In case of a tie (i.e. multiple characters appear with the same frequency), output the lexicographically smallest character.
Let \( s \) be the input string. Define the frequency function \( f(c) \) as the number of times character \( c \) occurs in \( s \). You need to find the character \( c^* \) such that
[ f(c^*) = \max_{c \in s} f(c), ]
and for any other character \( d \) with \( f(d) = f(c^*) \), it holds that \( c^* \leq d \) (in lexicographical order).
For example, for the input string "aabbbccde", the character 'b' appears 3 times which is the maximum, so the answer is 'b'.
inputFormat
The input consists of a single line containing a non-empty string s
of lowercase English letters.
outputFormat
Output a single character which is the most frequent character in s
. If there is more than one, output the lexicographically smallest one.
aabbbccde
b