Practice/Meta/Leetcode 1268. Search Suggestions System
CodingOptional
You are building an autocomplete feature for an e-commerce search bar. Given a list of product names and a search query that a user is typing character by character, return suggestions for each prefix of the search query.
For each prefix (formed by typing the search word one character at a time from left to right), return up to three product names that:
Return a list of suggestion lists, one for each character typed in the search word.
searchWord (from the first character to the complete word)Example 1:
` Input: products = ["mobile", "mouse", "moneypot", "monitor", "mousepad"] searchWord = "mouse"
Output: [ ["mobile", "moneypot", "mouse"], ["mouse", "mousepad"], ["mouse", "mousepad"], ["mouse", "mousepad"], ["mouse", "mousepad"] ]
Explanation:
Example 2:
` Input: products = ["havana"] searchWord = "tatiana"
Output: [[], [], [], [], [], [], []]
Explanation: No products start with 't', so all prefixes return empty lists. `
Example 3:
` Input: products = ["code", "coder", "coding", "codable", "codec", "codecs", "coded", "codes"] searchWord = "code"
Output: [ ["code", "codable", "codec"], ["code", "codable", "codec"], ["code", "codable", "codec"], ["code", "codable", "codec"] ]
Explanation: For each prefix of "code", the first 3 alphabetically are: code, codable, codec. `