Count runs that sum to k
Given a list of integers nums (it may contain negatives and zeros) and an integer k, return how many non-empty contiguous subarrays have a sum of exactly k. 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 (6,000 numbers) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
count_runs([1,1,1], 2)→2count_runs([1,2,3], 3)→2count_runs([1,-1,0], 0)→3