Implement prefix and suffix file search
InstacartSoftware Engineer · Online AssessmentLast updated
This question evaluates the ability to design and implement efficient string-indexing data structures and APIs for prefix-and-suffix matching, demonstrating competency with tries, suffix-related structures, inverted indexes, and time/space complexity trade-offs.
Implement data structures and APIs to store file names and support efficient queries that match both a given prefix and suffix. Provide methods add(name: string) and find(prefix: string, suffix: string) -> list of names (or IDs) that match both constraints, returning results in lexicographic order. Support up to 100,000 insertions and many queries with near-real-time updates; analyze time and space complexity and discuss alternatives (e.g., two tries, suffix automaton, inverted indexes).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.