Error rate alert trigger
Your task
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.
Examples
first_alert_index(flags: list[int], window: int, k: int) -> intExample 1
Input
first_alert_index([0, 1, 0, 1, 1, 0], 3, 2)Output
3