Given an array of integers nums and an integer k, return the total number of continuous subarrays whose sum equals k.
To keep the runner simple, input is provided as:
nums)kInput:
[1,1,1]
2
Output: 2
Input:
[1,2,3]
3
Output: 2
In the first example, the subarrays [1,1] (starting at index 0)
and [1,1] (starting at index 1) both sum to 2.
Your program must print only a single integer - the total count of valid subarrays - so it can be compared with the expected output.
No submissions yet.
Discuss brute force vs prefix-sum + hashmap approaches, time complexity, and handling of negative numbers.