Most Frequent Letter

Interview

Time limit2sMemory limit128 MB

Summary
Count letter frequencies in a string, case-insensitively, and print the most common letter in uppercase or a question mark on ties.
Level

Easy2 of 10

Topics
Hash map, String, Implementation
Solved
No attempts yet

Problem

Given a word made of uppercase and lowercase English letters, determine which alphabet letter appears most often. Uppercase and lowercase versions of the same letter are treated as the same letter.

Input

The first line contains a word made of uppercase and lowercase English letters. The length of the word is at most 1,000,000.

Output

Print the most frequent letter in uppercase on the first line. If two or more letters are tied for the highest frequency, print ?.

Examples4

  1. Example 1

    Input
    Mississipi
    
    Expected output
    ?
    
  2. Example 2

    Input
    zZa
    
    Expected output
    Z
    
  3. Example 3

    Input
    z
    
    Expected output
    Z
    
  4. Example 4

    Input
    baaa
    
    Expected output
    A