Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-334

Most Frequent Token Tiebreak

Problem

The most frequent token is the mode; on ties, prefer the token that appears first in the text (stable selection).

Given the token list, return the most frequent token, or None for an empty list.

Hint

Update the best token only on a strict improvement.

Test cases

case 1
in: [["a","b","b","a"]]
expected: "b"
case 2
in: [["x","y"]]
expected: "x"
case 3
in: [[]]
expected: null
Starter codePython
def most_frequent_token_tiebreak(tokens):
    # Your code here
    pass

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