560. Subarray Sum Equals K
Practice Subarray Sum Equals K for free on NudgeCode: Medium, Array & Hash Table pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Count how many contiguous, non-empty subarrays of nums add up to exactly k. Values can be negative, so a sliding window won't work.
Example
nums = [1,2,3], k = 3 -> 2 ([1,2] and [3])
Constraints
- 1 <= nums.length <= 2 * 10^4
- -1000 <= nums[i] <= 1000
- -10^7 <= k <= 10^7