Code Room
CodingMediumcod-g877
Subject Stream processingLevel Mid–Senior~25 minCommon in Distributed systems · Algorithms & data structures interviewsIndustries Software development, Technology

Question

Given a numeric stream and a window size, flag anomaly indices. For each index `i` with at least `window` prior values, compute the mean and population standard deviation of the immediately preceding `window` values (indices `i-window .. i-1`); index `i` is a spike if `stream[i] > mean + 2*std`. Return the list of spike indices in increasing order. Indices before a full trailing window exists are never flagged.

Implement
detect_spikes(stream: list[int], window: int) → list[int]
Examples
in[[1,1,1,1,50],4]out[4]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.