Count runs with a sum divisible by k
Given a list of integers nums (it may be empty and may hold negatives and zeros) and a positive integer k, return how many non-empty contiguous subarrays have a sum that is a multiple of k. A sum of 0 counts. Subarrays at different positions count separately, even when they hold the same values.
Aim for one pass over nums.
Besides the tests, one large input (4,000 numbers) with a ~150 ms limit (scaled to your device's speed): brute force won't pass.
Examples
count_divisible([2,-6,3,1,4,-5], 4)→7count_divisible([3,1,2], 3)→3count_divisible([7], 7)→1