Return how many contiguous runs of nums have a sum that is divisible by k (the sum can be 0, and it can be negative). Runs at different positions count separately.
The starter code tries every start and end. It is correct but too slow. Make it fast.
Example 1
Input:
subarrays_divisible_by_k([4, 5, 0, -2, -3, 1], 5)
Output:
7
Seven runs have a sum divisible by 5.
Example 2
Input:
subarrays_divisible_by_k([5], 9)
Output:
0
The only run has sum 5, not divisible by 9.
0 <= len(nums) <= 2 * 10**5-10**4 <= nums[i] <= 10**41 <= k <= 10**4No results yet
Run your code to check it against the examples, or submit to run every test.