FunctionRacerProblemsRace

Leading Word Tracker

EasyClassesPython, JavaScript, TypeScript, Java, C++

Implement a class WordTracker that counts the words in lines of text as they arrive and knows which word is in the lead. Write these methods:

The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.

Example 1

WordTracker()
add_line("the cat saw the dog") returns 5
top_word() returns "the"
add_line("dog dog") returns 2
top_word() returns "dog"
count_of("the") returns 2
count_of("cow") returns 0

After the first line the leads with 2. The second line takes dog to 3, which is more than 2, so dog leads.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Classes problems