All problems
Anomaly Window Detection
Problem
Count sliding windows of length window whose mean deviates from the overall mean by more than k population standard deviations: abs(window_mean - mean) > k * std.
Return 0 if window is not positive, window exceeds the series length, or the series has zero variance.
Hint
Compare each window mean to the global scale, and use a strict inequality.
Test cases
case 1
in: [[1,1,1,1,10,10],1,2]
expected: 1
case 2
in: [[1,2,3,4,5],0.5,1]
expected: 4
case 3
in: [[5,5,5,5],1,2]
expected: 0
case 4
in: [[1,2,1,2],10,2]
expected: 0
Starter codePython
def anomaly_window_detection(series, k, window):
# Your code here
pass4 test cases · run your code against them in the editor