values and two numbers, limit and divisor. Count the distinct non-empty contiguous segments of the array that contain at most limit elements divisible by divisor.
Two segments are the same if they match element by element (same length, same numbers in the same places), even when they come from different parts of the array.
An O(n²) solution exists.values=[1, 4, 1], limit=1, divisor=4 → 5
Only one number is divisible by 4, so every segment qualifies. Five of them are distinct: [1], [4], [1, 4], [4, 1] and [1, 4, 1]; the second [1] repeats the first.
values=[5, 10, 5], limit=1, divisor=5 → 2
Every number is divisible by 5, so only single-element segments qualify: [5] and [10].
values=[1, 4, 1], limit=1, divisor=4
5
Run checks the first 3 tests in your browser. Submit checks all 119 tests on the server, hidden ones included.