As reported: PayPal Engineer Full Stack, online assessment (2025): a medium DSA question — a search suggestion system.
Given an array of products and a searchWord, after each character of searchWord is typed, suggest at most three product names that start with the typed prefix. If more than three match, return the three lexicographically smallest. Return a list of lists: the suggestions after each character.
This is LeetCode 1268 — Search Suggestions System.
Example 1
products = ["mobile","mouse","moneypot","monitor","mousepad"], searchWord = "mouse"
-> [["mobile","moneypot","monitor"],
["mobile","moneypot","monitor"],
["mouse","mousepad"],
["mouse","mousepad"],
["mouse","mousepad"]]
Example 2
products = ["havana"], searchWord = "havana"
-> [["havana"],["havana"],["havana"],["havana"],["havana"],["havana"]]
Constraints: 1 ≤ products.length ≤ 1000; 1 ≤ products[i].length ≤ 3000; total characters ≤ 2·10^4; all products distinct; 1 ≤ searchWord.length ≤ 1000; lowercase letters only.
Code runner format: one JSON value per line: products, then searchWord. Implement suggestedProducts(products, searchWord); the harness prints the list of lists.