25 · Tries

#1268 Search Suggestions System

Mediumsolve on LeetCode ↗

frequently reported atAmazonOracleAdobeGoogleMeta

the problem

In plain words

After each character typed of searchWord, suggest up to 3 products (lexicographically smallest) that start with the typed prefix. Return the list of suggestion lists.

in products = ["mobile","mouse","moneypot","monitor","mousepad"], searchWord = "mouse"

out [["mobile","moneypot","monitor"],["mobile","moneypot","monitor"],["mouse","mousepad"],["mouse","mousepad"],["mouse","mousepad"]]

in products = ["havana"], searchWord = "tatiana"

out [[],[],[],[],[],[],[]]

  • 1 ≤ products.length ≤ 1000
  • 1 ≤ Σ products[i].length ≤ 2·10⁴
  • All products unique, lowercase
  • 1 ≤ searchWord.length ≤ 1000

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #208
    2. #35
      Search Insert Position
      Easyin Binary Search
    3. #347