LeetCode 1268 Search Suggestions System - Solution

The core idea

Sort products first. Then use binary search or a trie to find matches for each prefix.

Simple approach: sort products, then for each prefix, binary search to find the first product >= prefix. Check the next 3 products to see if they match the prefix.

Trie approach: insert all products. For each prefix, traverse the trie and DFS to collect up to 3 words.

The sorted + binary search approach is simpler and often faster for this problem size.