415. Binary Subarrays With Sum
MediumPrefix Sum
The array has only 0s and 1s. Count the non-empty contiguous subarrays whose sum equals goal.
Input format
Line 1: n goal Line 2: n bits
Output format
The count.
Example 1
Input
5 2 1 0 1 0 1
Output
4
Example 2
Input
5 0 0 0 0 0 0
Output
15
Constraints
1 ≤ n ≤ 10⁵
Read input from standard input and print the answer to standard output. Your code is judged against 5 test cases, most of them hidden.
Loading the MyLoginn IDE…