ntree.aiSearch Suggestions System
Search Suggestions System
mediumsolvedattempted
Given an array of strings products and a string searchWord, return an array of products with matched prefixes for each prefix of searchWord.
For each prefix, return products in the lexicographic order, at most three first ones.
Example 1:
Input: products = ["bat", "map", "mop", "mou", "mud"], searchWord = "mou"
Output: [["map", "mop", "mou"], ["mop", "mou"], ["mou"]]
Example 2:
Input: products = ["havana"], searchWord = "tatiana"
Output: [[], [], [], [], [], [], []]
Explanation: no product starts with "t", so every suggestion list is empty.
Constraints:
1 <= length of products <= 10001 <= length of products[i], length of searchWord <= 1000products[i]andsearchWordcontain lowercase English letters only
def suggestedProducts(products: list[str], searchWord: str) -> list[list[str]]: pass Press Visualise to step through your code.