Suggested Products
Updated
Problem statement
You are given an array of unique strings products and a string search. As each character of search is typed, show the products that start with the typed prefix.
Show at most three of them: the three lexicographically smallest, in sorted order. Return one list of suggestions for each typed character.
Function
suggestedProducts(products: String[], search: String) → List<List<String>>Examples
Example 1
products = ["abcd", "abba", "adbc", "abcc"]search = "abcd"return = [["abba", "abcc", "abcd"], ["abba", "abcc", "abcd"], ["abcc", "abcd"], ["abcd"]]
The function should return a list of lists of strings, where each list corresponds to the top 3
lexicographically smallest strings in products that match the prefix formed by the
search word up to that point.
Step 1: Word = "a", Matching Prefix Products = ["abba", "abcc", "abcd"] Step 2: Word = "ab", Matching Prefix Products = ["abba", "abcc", "abcd"] Step 3: Word = "abc", Matching Prefix Products = ["abcc", "abcd"] Step 4: Word = "abcd", Matching Prefix Products = ["abcd"]
Constraints
1 <= products.length <= 1000.1 <= products[i].length <= 3000.- The total length of all products is at most
2 * 10^4. - All products are unique.
1 <= search.length <= 1000.products[i]andsearchcontain only lowercase English letters and digits.
More Squarepoint Capital interview questions
- Lazy Filter over a GeneratorPHONE SCREEN · Seen Nov 2026
- Moving Average of a Data StreamPHONE SCREEN · Seen Nov 2026
- Newton Square Root to a Guaranteed TolerancePHONE SCREEN · Seen Nov 2026
- Probability of Consecutive HeadsPHONE SCREEN · Seen Nov 2026
- Three Points in a Semicircle: Monte Carlo EstimatePHONE SCREEN · Seen Nov 2026
- Mutable Record Store with Error ResultsONSITE INTERVIEW · Seen Sep 2026
- Combine Two Index SequencesPHONE SCREEN · Seen Aug 2026
- Parse, Normalize, and Combine PolynomialsPHONE SCREEN · Seen Aug 2026
- Sorted Insertion SnapshotsPHONE SCREEN · Seen Aug 2026
- Strong and Weak Reference LifecyclePHONE SCREEN · Seen Aug 2026
Similar questions at other companies
- Find All Word Occurrences in TextSentry · PHONE SCREENSentry interview questions
- Highlight and Rank Overlapping CitationsHarvey · PHONE SCREEN · ONSITE INTERVIEWHarvey interview questions
- Keyboard Autocomplete SuggestionsLyft · ONSITE INTERVIEWLyft interview questions
- Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
- Search Suggestions with a Prefix TreeCitadel · ONSITE INTERVIEWCitadel interview questions
- Remove Prefix StringsRoblox · PHONE SCREENRoblox interview questions
- Every Distinct Substring in OrderAdobe · PHONE SCREENAdobe interview questions
- Shell Path AutocompleteFigma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
- Top K Query SuggestionsMicrosoft · PHONE SCREENMicrosoft interview questions
- Find the Words for Each PrefixDocuSign · PHONE SCREENDocuSign interview questions