Design streaming stats with sliding window
Company: Akuna Capital
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Design a data structure that ingests an integer stream and supports online queries for maximum, mean, and mode.
1) Describe your update and query operations and their time/space complexity.
2) If values are guaranteed to be in the range [1, 1001], propose an exact solution and compute the memory required to maintain the mode.
3) If the value domain is unbounded or memory is constrained, describe how you would approximate the mode, including the accuracy trade-offs.
4) Extend your design to support returning the max, mean, and mode over only the most recent k elements (a sliding window). Explain how you maintain these statistics as the window slides, analyze the complexity, and discuss how you handle ties and empty-window cases.
Overview: Design streaming stats with sliding window evaluates algorithm design, data structures, correctness, complexity, edge cases, and implementation details in a realistic interview setting. A strong answer states assumptions, handles edge cases, explains trade-offs, and shows how to validate the result clearly.