cswork / libraryOpen practice workspace

Interview questions · Instacart

Implement prefix and suffix file search

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).

Community answers

Nothing here yet.

Join in on CSWork →