Code RoomError rate alert trigger
MediumPrep Room Coding #518

Error rate alert trigger

CodingAlgorithms & data structuresEntry–Mid~13 min

A gateway tags each request with an error flag, giving you a list of 0s and 1s in arrival order (1 = failed request). The alerting rule watches the last `window` requests: it trips at the first position where the most recent `window` flags contain at least k ones. Return the smallest index i (0-based, counting from the window-th request, so i >= window - 1) where flags[i-window+1..i] holds k or more ones; return -1 if the rule never trips (including when fewer than `window` requests exist). Assume window >= 1 and k >= 1.

Implement
first_alert_index(flags: list[int], window: int, k: int) → int
Examples
in[[0,1,0,1,1,0],3,2]out3
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.

0:00 of about 13 min
InputExpectedGot
[[0,1,0,1,1,0],3,2]3not run yetsample