Search Suggestions System
MediumP2Coding
You are given an array of distinct lower-case products and a searchWord. As the user types searchWord one letter at a time, suggest at most three products after each letter: the products that start with the typed prefix, in lexicographic (alphabetical) order, taking the first three.
Return a list with one list of suggestions per typed letter.
Example 1
- Input
- products = ["mobile","mouse","moneypot","monitor","mousepad"], searchWord = "mouse"
- Output
- [["mobile","moneypot","monitor"],["mobile","moneypot","monitor"],["mouse","mousepad"],["mouse","mousepad"],["mouse","mousepad"]]
Example 2
- Input
- products = ["havana"], searchWord = "tatiana"
- Output
- [[],[],[],[],[],[],[]]
Constraints
- 1 <= products.length <= 1000
- 1 <= products[i].length <= 3000, total length of products <= 2 * 10^4
- products are distinct
- 1 <= searchWord.length <= 1000
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 9. ⌘Enter runs, ⌘⇧Enter submits.