#K3711. Most Frequent Character

    ID: 25904 Type: Default 1000ms 256MiB

Most Frequent Character

Most Frequent Character

Given a string \(s\), find the character that appears most frequently in \(s\). In case there is a tie between two or more characters, return the one that appears first in the string. If the string is empty, output -1.

Example:

  • For \(s = \"hello\"\), the answer is l because l appears twice while all other characters appear only once.
  • For \(s = \"test\"\), the answer is t because although both t and e appear, t comes first.
  • For an empty input, output -1.

The problem tests your understanding of frequency counting and maintaining order of appearance. Use of LaTeX is applied for mathematical formatting where applicable.

inputFormat

The input consists of a single line containing a string \(s\). The string may be empty.

Input is read from standard input (stdin).

outputFormat

Output a single character that is the most frequent in \(s\) according to the rules stated, or -1 if the string is empty.

Output is written to standard output (stdout).

## sample
hello
l