Arrays & HashingMedium

Subarray Sum Equals K

Count the contiguous runs in nums whose numbers add up to exactly k. Numbers can be negative.

Example 1nums = [1, 2, 1, 2], k = 3 → 3[1, 2], [2, 1] and [1, 2] again.
Example 2nums = [3, -3, 3], k = 3 → 3
1 ≤ n ≤ 2·10⁴ · −1000 ≤ nums[i] ≤ 1000

Hints

0 of 3 open
Hint 2 · the patternHint 3 · the key line