Compute sliding window sums by tag
Company: Datadog
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: This question evaluates understanding of sequence processing, sliding-window aggregation, filtering by tag, and efficient state management in tagged time-series or event data, testing algorithmic efficiency and correctness.
Constraints
- 1 <= n <= 200000, where n is the number of datapoints
- Each datapoint is a dict with keys: 'tags' (list[str]), 'ts' (int), 'value' (int)
- Tag strings are non-empty; tags list size 0..50
- Timestamps ts are integers and may repeat
- Values are integers in range [-1e9, 1e9]
- 1 <= k <= n; if the number of matching datapoints m < k, return []
- Order matching datapoints by ascending ts; if ts ties, preserve original input order
- Input datapoints are not guaranteed to be pre-sorted
Hints
- First filter datapoints whose tags contain the target tag.
- Sort the filtered list by timestamp ascending; preserve input order for equal timestamps.
- Maintain a running sum for the sliding window and update it in O(1) per step.