#K76457. Most Frequent Character
Most Frequent Character
Most Frequent Character
You are given a string s
. Your task is to find the most frequent character in the string. In the event of a tie (i.e. when two or more characters have the same highest frequency), output the character that appears first in the string. If the string is empty, output an empty string.
Formally, let \( f(c) \) be the frequency of character \( c \) in \( s \). Find the character \( c^* \) such that:
[ c^* = \min_{\substack{c \in s \ f(c) = \max_{d \in s} f(d)}} {\text{first occurrence of } c} ]
Read the input from standard input (stdin) and write the answer to standard output (stdout).
inputFormat
A single line containing the string s. The string may be empty.
outputFormat
Output a single line containing the most frequent character. In case of a tie, output the one that appears first in the string. If s is empty, output an empty string.## sample
abracadabra
a