2dbi
Home/Elastic/Search Suggestions (Trie / Prefix)
EElastic·DSAEngineerOnline Assessment

Search Suggestions (Trie / Prefix)

Problem

Given a product list and a search word typed character by character, return up to 3 lexicographically smallest suggestions for each prefix.

Example

products=[mobile,mouse,moneypot], word=mou -> suggestions per prefix

Constraints

  • 1 ≤ n ≤ 10^4

Approach

Trie or sorted array + binary search. Fits Elastic's search domain.

added 6 days ago
LeadersAccount