Back to problems

Optimize Word Container / String Matching Queries (ParanoidEcho)

Algorithm · Meta · Medium

Problem Design a string container that can answer prefix queries efficiently. Operations ADD word – inserts word into the container. Duplicates may be ignored. QUERY s – returns YES if the container holds at least one word that is a prefix of s; otherwise returns NO. You must implement a solution that is asymptotically faster than a brute‑force scan of every stored word for each query. Function Signature Each element of operations is a string that begins with either "ADD "…

Checking your access…