A search box shows up to three suggestions after every keystroke. The suggestions for the text typed so far are the stored words that start with it, in alphabetical order (normal string < order), keeping only the first three. Repeated words in the list count once.
Write suggestions(words, typed) that returns an array with one entry per keystroke: entry i is the list of suggestions for typed.slice(0, i + 1). A keystroke with no matching words gets [].
Input: words = ["modal","mount","module","monitor","mountain"], typed = "mou" Output: [["modal","module","monitor"],["modal","module","monitor"],["mount","mountain"]]
After m and mo all five match, so the first three alphabetically are shown. After mou only two match.
Input: words = ["tab","table"], typed = "tx" Output: [["tab","table"],[]]
Nothing starts with tx.
1 <= words.length <= 10001 <= typed.length <= 100Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #369 Suggestions as You Type. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.