LeetCode MEDIUM 930 Binary Subarrays With Sum Summary
Generated by Codex with GPT 5.6 Sol XHigh
Quick facts
- Difficulty:
MEDIUM - Problem: Binary Subarrays With Sum
- Topics:
Array,Hash Table,Sliding Window,Prefix Sum
Problem gist
Given a binary array nums and a nonnegative integer goal, count the nonempty contiguous subarrays whose elements add up to exactly goal.
Contiguous and exact are the important words. The same element may belong to many valid subarrays, and zeros create several subarrays with the same sum. For example, in [1, 0, 1, 0, 1], there are four different subarrays whose sum is 2.