Subarray Sum Equals K — prefix sums in a hashmap
A subarray sums to k exactly when two prefix sums differ by k. Count each match in one pass.
Try:
← Prev
Next →
▶ Play
Reset
sum =
0
need sum−k =
–
result =
0
prefix-sum counts seen so far