Most frequent word

EasyHashmap

Given a list of words, return the word that occurs most often.

If several words are tied, return the one that first appeared earliest in the list.

Case matters: “Cat” and “cat” are different words.

If the list is empty, return None.

Constraints: up to 100,000 words; the solution must run in O(n).

Examples

Show hint

You need to remember two things about each word: how many times it occurred, and where it first appeared.

Your solution

Ctrl/⌘ + Enter runs the examples, Ctrl/⌘ + Shift + Enter submits
Loading Python…