Your question is Time-Series Anomaly Detection. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Zoox autonomy telemetry arrives as a stream of numeric samples. Implement a robust online detector that identifies samples whose value is anomalous relative to the immediately preceding rolling window.
For each sample after the first complete window, calculate the window's median and median absolute deviation (MAD). Define the modified z-score as 0.6745 * abs(value - median) / MAD. Mark the sample anomalous when this score is greater than threshold. The current sample must not be included in its own baseline window.
If MAD == 0, mark the sample anomalous exactly when it differs from the window median. Return the zero-based indices of anomalous samples in ascending order.
detect_anomalies(values, window_size, threshold) receives a list of numeric values, a positive integer window size, and a positive numeric threshold. It returns a list of integer indices. Samples before the first complete prior window are never anomalous.
def detect_anomalies(values, window_size, threshold):