FunctionRacerProblemsRace

Word Chain Game

EasyClassesPython, JavaScript, TypeScript, Java, C++

Implement a class WordChain for a word game: every word must start with the last letter of the word before it, and no word may be used twice. 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

WordChain()
play("apple") returns true
play("egg") returns true
play("goat") returns true
play("tea") returns true
play("apple") returns false
play("ant") returns true
get_longest_word() returns "apple"
count_words() returns 5

apple would follow tea by its first letter, but it is already in the chain, so it is refused. ant is accepted instead, and apple is still the longest word.

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