Binary Subarrays With Sum Problem

Binary Subarrays With Sum Problem — ExecCode Easy DSA Practice

Solve the Binary Subarrays With Sum problem on ExecCode. Free online easy DSA practice in Sliding Window. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given a binary array nums and an integer goal, return the number of non-empty subarrays with a sum goal. Your task is to a subarray is a contiguous part of the array. Return the required answer exactly as shown in the examples.

Examples

Input {"nums": [1, 0, 1, 0, 1], "goal": 2}; Output 4. Input {"nums": [0, 0, 0], "goal": 0}; Output 6. Input {"nums": [1, 0, 0, 1], "goal": 1}; Output 6

Constraints

1 <= nums.length <= 3 * 10^4 nums[i] is either 0 or 1. 0 <= goal <= nums.length

Practice Binary Subarrays With Sum free on ExecCode. Browse DSA problems, topic map, and placement guides.