#K9416. Most Frequent Character
Most Frequent Character
Most Frequent Character
You are given a string s
. Your task is to determine the character that appears most frequently in s
. In the case of a tie, the lexicographically smallest character (according to the ASCII order) should be returned.
More formally, let \( f(c) \) denote the frequency of character \( c \) in the string \( s \). You need to find the character \( c^* \) such that:
[ c^* = \min { c \mid f(c)=\max_{x \in s} f(x) } ]
For example, if the input string is "abracadabra", the answer is "a" because \( f(a)=5 \) and no other character appears more frequently.
inputFormat
The input consists of a single line that contains the string s
. The string may include spaces and other printable characters.
outputFormat
Output a single character — the most frequent character in the string. In case of multiple characters having the same frequency, output the lexicographically smallest one.
## samplea
a