bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1268. Search Suggestions System

1268. Search Suggestions System

Leetcode Solutions

Approach: Binary Search

  1. Sort the products array.
  2. Initialize an empty list result to store the lists of suggestions.
  3. For each character in searchWord, do the following: a. Add the character to the current prefix. b. Perform a binary search on products to find the first product that matches the prefix. c. From the index found, add up to three products to the current list of suggestions. d. Append the current list of suggestions to result.
  4. Return result.
UML Thumbnail

Approach: Trie + DFS

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...