#C4852. Most Frequent Character
Most Frequent Character
Most Frequent Character
Given a string s, find the most frequent character in the string. In case of a tie, return the lexicographically smallest character.
If the input string is empty, output None
.
The problem requires you to process the string and compute the frequency of each character. You then determine which character has the highest frequency. In the event of a tie, the character with the smaller ASCII value (i.e. lexicographically smaller) should be chosen.
The formula for frequency analysis is given as follows:
\[ \text{Frequency}(c) = \sum_{i=1}^{n} \mathbf{1}_{\{s_i = c\}}, \] where \(\mathbf{1}\) is the indicator function and \(s_i\) is the i-th character of the string.
inputFormat
The input consists of a single line containing the string s. Note that s may be empty.
outputFormat
Output a single line which contains the most frequent character in the string. If the string is empty, output None
.
aabbbcc
b