Approach hintTry it first, then revealHide
A subarray ending at i sums to k when some earlier prefix equals pre[i] - k. Count prefix values in a hash map as you go, seeded with prefix 0; negative numbers rule out a sliding window.
A subarray ending at i sums to k when some earlier prefix equals pre[i] - k. Count prefix values in a hash map as you go, seeded with prefix 0; negative numbers rule out a sliding window.