Small example
Input
nums = [1,1,1], k = 2
Output
2
Subarrays [1,1] at indices (0,1) and (1,2).
Full lesson preview
Count the number of continuous subarrays whose sum equals k using prefix sums and a hash map.
Problem statement
Task
Examples
Input
nums = [1,1,1], k = 2
Output
2
Subarrays [1,1] at indices (0,1) and (1,2).
Input format
Output format
Constraints
Samples
Input
nums = [1,2,3], k = 3
Output
2
Subarrays [1,2] and [3].