LeetCode 560 Subarray Sum Equals K - Problem Statement

The problem

Given an array of integers nums and an integer k, return the total number of subarrays whose sum equals k.

With nums = [1, 1, 1] and k = 2, the answer is 2. The subarrays [1, 1] starting at index 0 and starting at index 1 both sum to 2.

Note: subarrays must be contiguous. This isn't about subsets. How can prefix sums help you count these efficiently?

Constraints: 1n2×1041 \le n \le 2 \times 10^4, values from 1000-1000 to 10001000.