Count the number of contiguous subarrays whose elements sum to a given target.
Given a binary array and an integer goal, count how many contiguous subarrays have sum exactly equal to the goal.
A subarray must be non-empty and consist of consecutive elements from the array. Because the array contains only 0s and 1s, efficient counting techniques are often more useful than checking every subarray directly.
Input Format
- An integer array
numscontaining only0and1 - An integer
goal
The exact input encoding depends on the platform.
Output Format
Return the number of contiguous subarrays whose sum is exactly goal.
Constraints
1 <= nums.lengthis assumed to be moderate to largenums[i]is either0or1goalis a non-negative integer
Use the platform's official limits if available.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.