← All problems
Subarray Sum Equals K (hashmap drill)
Count the number of contiguous subarrays summing to k using prefix sums and a hash map, in O(n) time. Explain why the map stores prefix-sum frequencies.
Complexity
Time O(n), Space O(n)
Common pitfalls
- Query-after-update order swapped
- Sliding window on negatives
Your solution
Log in to save your code and track progress.