values (negatives and zeros allowed) and a number divisor. A window is a non-empty run of consecutive elements.
Count the windows whose sum is evenly divisible by divisor. Windows at different positions count separately, even if their values match.
Checking every window takes O(n²); try to find an O(n) solution.values=[3, -1, 4, 2], divisor=3 → 4
Four windows have a sum divisible by 3: [3] = 3, [-1, 4] = 3, [4, 2] = 6 and [3, -1, 4] = 6.
values=[5], divisor=2 → 0
The only window sums to 5, which is odd.
values=[0, 0], divisor=7 → 3
Zero is divisible by anything, so all three windows count: [0], [0] and [0, 0].
values=[3, -1, 4, 2], divisor=3
4
Run checks the first 3 tests in your browser. Submit checks all 109 tests on the server, hidden ones included.