Loading Now

twoGram

Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" are three distinct two-grams.

You are given a string s consisting of capital Latin letters. Your task is to find two-gram contained in the given string as a substring (i.e. two consecutive characters of the string) maximal number of times. For example, for string s = "BBAABBBA" the answer is two-gram "BB", which contained in s three times. In other words, find most frequent two-gram. If there are different two-gram, return the lexicographically smallest one.

Note that occurrences of the two-gram can overlap with each other.

Example

  • For s = “BBAABBBA" the output should be twoGram(s) = "BB"

Input/Output

  • [Execution time limit] 0.5 seconds

  • [Input] string s

    Guaranteed constraints:
    1 <= |s| <= 100
  • [Output] integer

The most frequent two-gram.

Post Comment

Contact