FunctionRacerProblemsRace

Search Box Suggestions

HardClassesPython, JavaScript, TypeScript, Java, C++

Implement a class SearchBox that suggests searches while someone types. It remembers how often every phrase was searched and offers the most popular phrases that begin with what has been typed so far. 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

SearchBox(2)
record("cat", 2)
record("cab", 3)
type_letter("c") returns ["cab","cat"]
type_letter("a") returns ["cab","cat"]
type_letter("t") returns ["cat"]
submit() returns "cat"
type_letter("c") returns ["cab","cat"]

After typing c, both phrases fit and cab, searched 3 times, comes before cat. Typing a and t leaves only cat. Submitting counts cat once more, so now both phrases have 3 searches and the alphabet decides.

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