Mental Model
We keep track of sums of numbers from the start to each position and use a map to find if a previous sum allows a subarray to sum to k.
Analogy: Imagine walking along a path and counting steps. If you know the total steps at two points, subtracting them tells you how many steps you took between those points. The map remembers these totals to quickly find matching distances.
Array: [1, 2, 3, 4]
Prefix sums: 0 -> 1 -> 3 -> 6 -> 10
HashMap stores sums seen so far with their counts:
{0:1, 1:1, 3:1, 6:1, 10:1}
Looking for subarray sum k=6 means checking if current_sum - k exists in map.