- Search Suggestion System
For an array of n strings products and a word to search, search, designa system that, when each character of the searched word is typed,suggests at most three product names from the products array. Thesuggested products should share a common prefix with the searchedword. lf more than three products exist with a common prefix, reportthe three product names that appear first in lexicographical order.
Return the suggested products, which will be a list of lists after eachcharacter of the searched word is typed.
Note: A string xis considered lexicographically smaller than anotherstring yif xwill occur before yin the English dictionary.
ExampleSuppose n = 5, products = ["carpet", "cart", "car", "camera", "crate"],and search = "camera".
![](https://csoahelp.com/wp-content/uploads/2023/09/dbf56a5b8a2c85ee60aafd5afab1cd9-1024x845.png)
![](https://csoahelp.com/wp-content/uploads/2023/09/abb48916ce116c01bd98129cc12c6ed-1024x1010.png)
![](https://csoahelp.com/wp-content/uploads/2023/09/7d3e20452ba5b7832550c2d50b95e05-1024x465.png)
![](https://csoahelp.com/wp-content/uploads/2023/09/d40cd68b600bcc851208510cf6b2f45-1024x535.png)
扫码联系我
![](https://csoahelp.com/wp-content/uploads/2023/07/1-5.png)