Match logs to prior queries
Company: Datadog
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates understanding of streaming algorithms, string indexing, and set-based matching, focusing on designing efficient online data structures to match stored queries against incoming logs within the Coding & Algorithms domain.
Constraints
- 1 <= len(lines) <= 200000
- Each line starts with exactly "Q: " or "L: "
- Each query and log contains at least one word after the prefix
- Words are separated by single spaces and contain no spaces themselves
- Matching is case-sensitive
- Let T be the total number of words across all lines; T <= 2,000,000
Hints
- Index each query by its set of distinct words and store the required count per query.
- Build an inverted index: word -> list of query IDs containing that word.
- For each log, take its distinct words and accumulate counts per candidate query ID using the inverted index; a query matches if its seen count equals its required count.