The Spike
A hard Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- hard
- Seniority
- L6
Problem
A monitoring service emits readings as `(timestamp, value)` pairs in time order, and on-call needs the points that jump away from their recent baseline. Walking the readings in order, treat a reading at index `window` or later as anomalous when its distance from the mean of the `window` readings immediately before it (the current reading excluded) is more than `threshold` times their population standard deviation. Skip the opening readings that lack a full history and any stretch where those prior readings are identical, and for each anomaly return a dict with `timestamp`, `value`, `rolling_mean`, `rolling_std`, and `z_score` (the signed count of standard deviations from the mean), every numeric field rounded to two decimals, in scan order.
Summary
Spot the outliers before they page someone.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and grades it automatically.