This question evaluates understanding of prefix-based string matching, data structure design (hash-based sets and trie/prefix tree), and algorithmic competencies including efficient in-memory storage and deduplication of matches.
Design a data structure that stores a collection of prefix strings. Then, given a list of input strings, return every string that begins with at least one stored prefix.
Requirements:
addPrefix(prefix)
to store a prefix.
Example:
["ab", "cat", "pre"]
["abc", "dog", "prefix", "cater", "zoo"]
["abc", "prefix", "cater"]
Follow-up: