Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-017

Most Common Token

Problem

Return the token with the highest frequency. Break ties by choosing the lexicographically smallest token, comparing plain strings.

Return an empty string for empty input.

Hint

Iterate over sorted keys and keep the first maximum you see.

Test cases

case 1
in: [["b","a","b","c"]]
expected: "b"
case 2
in: [["a","b","c","a","b"]]
expected: "a"
case 3
in: [[]]
expected: ""
case 4
in: [["z","z","y","y"]]
expected: "y"
case 5
in: [["only"]]
expected: "only"
Starter codePython
def most_common_token(tokens):
    # Your code here
    pass

5 test cases · run your code against them in the editor