660. Search Suggestions System
0
Medium
We need to create a system that suggests up to three product names from a given list of products after each character of a search word is entered. The suggested products should have a common prefix with the search word. If there are more than three products with a common prefix, we should return the three lexicographically smallest products. The output should be a list of lists, showing the suggested products after each character of the search word is entered.
Input Format
The first line of input represents N, the number of words. The next N lines contain the words to be searched. The last line contains the search word.
Output Format
The desired output is a list of words.
Example
Input
5
mobile
mouse
moneypot
monitor
mousepad
mouse
Output
[["mobile", "moneypot", "monitor"], ["mobile", "moneypot", "monitor"], ["mouse", "mousepad"], ["mouse", "mousepad"], ["mouse", "mousepad"]]
Constraints
The number of words to be searched is less than 1000.
Loading...
View Submissions
Console