Count subarrays that sum to K

0
Remix

Given an array of integers (negatives allowed) and k, count the contiguous subarrays whose sum is exactly k. Keep running prefix sums and a map from each prefix sum to how often it has appeared.

AppleTechnical phone screenLast asked Feb 2026
No answer yet. Write the first one; the best answer gets endorsed.