Solving Binary Subarrays With Sum in go. Please try yourself first to solve the problem and submit your implementation to LeetCode before looking into solution.

Problem Description

In an array A of 0s and 1s, how many non-empty subarrays have sum S?

Example 1:

Input: A = [1,0,1,0,1], S = 2
Output: 4
Explanation: 
The 4 subarrays are bolded below:
[1,0,1,0,1]
[1,0,1,0,1]
[1,0,1,0,1]
[1,0,1,0,1]

Note:

  • A.length <= 30000
  • 0 <= S <= A.length
  • A[i] is either 0 or 1.

See the full details of the problem Binary Subarrays With Sum at LeetCode

Originally posted at: @github.com/halfrost/LeetCode-Go