1268. Search Suggestions System
1268. Search Suggestions System
Description
You are given an array of strings products
and a string searchWord
.
Design a system that suggests at most three product names from products
after each character of searchWord
is typed. Suggested products should have common prefix with searchWord
. If there are more than three products with a common prefix return the three lexicographically minimums products.
Return a list of lists of the suggested products after each character of searchWord
is typed.
Example 1:
1 | Input: products = ["mobile","mouse","moneypot","monitor","mousepad"], searchWord = "mouse" |
Example 2:
1 | Input: products = ["havana"], searchWord = "havana" |
Constraints:
1 <= products.length <= 1000
1 <= products[i].length <= 3000
1 <= sum(products[i].length) <= 2 * 10^4
- All the strings of
products
are unique . products[i]
consists of lowercase English letters.1 <= searchWord.length <= 1000
searchWord
consists of lowercase English letters.
Hints/Notes
- 2025/02/28 Q2
- Trie
- Leetcode solution
Solution
Language: C++
1 | class Solution { |