This is Subarray Sum Equals K from LeetCode. It's one of the most common prefix sum interview questions. Given an array of integers and an integer , return the total number of subarrays whose sum equals .
At first, you might try checking every subarray. That's subarrays, and even with prefix sums, you're still doing comparisons. Can you do better?