Search Suggestions System Problem
Search Suggestions System Problem — ExecCode Medium DSA Practice
Solve the Search Suggestions System problem on ExecCode. Free online medium DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given an array of product names and a search word, design a system that suggests at most three lexicographically-smallest matching products after each character the user types. Return a list where each entry corresponds to one character typed so far, containing up to three products from the catalog that start with the prefix typed up to that point.
Examples
Input products = ["mobile", "mouse", "moneypot", "monitor", "mousepad"], searchWord = "mouse"; Output [["mobile", "moneypot", "monitor"], ["mobile", "moneypot", "monitor"], ["mouse", "mousepad"], ["mouse", "mousepad"], ["mouse", "mousepad"]]. Input products = ["havana"], searchWord = "havana"; Output [["havana"], ["havana"], ["havana"], ["havana"], ["havana"], ["havana"]]. Input products = ["bags", "baggage", "banner", "box", "cloths"], searchWord = "bags"; Output [["baggage", "bags", "banner"], ["baggage", "bags", "banner"], ["baggage", "bags"], ["bags"]]
Constraints
1 <= products.length <= 1000 1 <= products[i].length, searchWord.length <= 3000 products[i] and searchWord consist of lowercase English letters
Practice Search Suggestions System free on ExecCode. Browse DSA problems, topic map, and placement guides.