NumPy allowed · plain Python earns 10 bonus points
Implement Subarray Sum Equals K via the prefix-sum-plus-hash-map trick -- the technique that makes this solvable in O(n) even with negative numbers present, where a sliding window would fail.
Implement subarray_sum(nums, k): track a running prefix sum and a hash map of "how many times has each prefix sum value occurred so far." A subarray ending at the current position sums to k exactly when (current prefix sum - k) has occurred before -- add that count to the running total.
subarray_sum(nums: list[int], k: int) -> int