Back to problems

Implement Prefix Match Filter

Algorithm · Datadog · Medium

Design a data structure that stores a set of prefix strings and then filters a list of query strings. A query string is retained when it starts with at least one stored prefix. The structure must support: addPrefix(prefix) — inserts a prefix into the collection. matches(word) — returns true when word starts with any stored prefix. filter(words) — returns every matching word from words. A prefix is any leading contiguous portion of a word, including the empty prefix. If the…

Checking your access…