Loading...
The Middle Ground
A hard Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- hard
- Seniority
- senior
Problem
The monitoring pipeline ingests latency samples one at a time, and the alerting system needs the current median at any point to detect drift. Sorting the entire history on every query is too slow. Build a class that accepts numbers one at a time and returns the running median efficiently. For an even count, return the average of the two middle values. Querying before any data is added should raise a ValueError.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a sandboxed Docker environment and grades it instantly.