Company: Wayfair

Difficulty: medium

Problem Statement

Question 2 You are building the autocomplete box for a storefront. Given an array of n strings products holding the catalog names, and a string search that a shopper is typing one letter at a time, produce up to three catalog names to suggest after every keystroke. A suggestion qualifies only if it starts with the letters typed so far. When more than three catalog names qualify at some point, keep the three that come first alphabetically. Return, for each prefix of search (from the first letter typed through the full word), the list of suggestions shown at that moment — an overall list of lists. Note: A string x is considered lexicographically smaller than another string y if x will occur before y in the English dictionary. Function Description Complete the function getProductSuggestions in the editor below. getProductSuggestions has the following parameter(s): string products[n] : the list of products string search : a string Returns string[n][] : for each prefix of the string, return

More Wayfair OA questionsInterview experiences