1268. Search Suggestions System Medium

@problem@discussion
#Array#String#Trie



1/**
2 * [1268] Search Suggestions System
3 *
4 * You are given an array of strings products and a string searchWord.
5 * 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.
6 * Return a list of lists of the suggested products after each character of searchWord is typed.
7 *  
8 * <strong class="example">Example 1:
9 * 
10 * Input: products = ["mobile","mouse","moneypot","monitor","mousepad"], searchWord = "mouse"
11 * Output: [["mobile","moneypot","monitor"],["mobile","moneypot","monitor"],["mouse","mousepad"],["mouse","mousepad"],["mouse","mousepad"]]
12 * Explanation: products sorted lexicographically = ["mobile","moneypot","monitor","mouse","mousepad"].
13 * After typing m and mo all products match and we show user ["mobile","moneypot","monitor"].
14 * After typing mou, mous and mouse the system suggests ["mouse","mousepad"].
15 * 
16 * <strong class="example">Example 2:
17 * 
18 * Input: products = ["havana"], searchWord = "havana"
19 * Output: [["havana"],["havana"],["havana"],["havana"],["havana"],["havana"]]
20 * Explanation: The only word "havana" will be always suggested while typing the search word.
21 * 
22 *  
23 * Constraints:
24 * 
25 * 	1 <= products.length <= 1000
26 * 	1 <= products[i].length <= 3000
27 * 	1 <= sum(products[i].length) <= 2 * 10^4
28 * 	All the strings of products are unique.
29 * 	products[i] consists of lowercase English letters.
30 * 	1 <= searchWord.length <= 1000
31 * 	searchWord consists of lowercase English letters.
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/search-suggestions-system/
37// discuss: https://leetcode.com/problems/search-suggestions-system/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn suggested_products(products: Vec<String>, search_word: String) -> Vec<Vec<String>> {
43        vec![]
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_1268() {
55    }
56}
57


Back
© 2025 bowen.ge All Rights Reserved.