#C13287. Most Frequent Character

    ID: 42808 Type: Default 1000ms 256MiB

Most Frequent Character

Most Frequent Character

Given a string s consisting only of lowercase alphabets (i.e. a-z) and of length at least 1, find the character that appears most frequently in s. In the case of a tie, return the character that appears first in s.

You can formalize the problem as follows:

Let \(F(c)\) be the frequency of character \(c\) in the string \(s\). Find \(c^*\) such that \(F(c^*) \geq F(c)\) for any character \(c\) in \(s\), and if there exists a tie, \(c^*\) is the one with the smallest index in \(s\).

Example:

  • Input: "test"; Output: "t"
  • Input: "character"; Output: "c"

inputFormat

Input is provided via standard input (stdin) as a single line containing a string s that consists only of lowercase English letters.

outputFormat

The output should be written to standard output (stdout) and is a single character: the most frequent character in the string s. In case of a tie, the character that appears first in the string should be printed.

## sample
test
t