Design a data structure that ingests an integer stream and supports online queries for maximum, mean, and mode.
-
Describe your update and query operations and their time/space complexity.
-
If values are guaranteed to be in the range [1, 1001], propose an exact solution and compute the memory required to maintain the mode.
-
If the value domain is unbounded or memory is constrained, describe how you would approximate the mode, including the accuracy trade-offs.
-
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.