#3728
Stable Subarrays With Equal Boundary and Interior Sum
medium · 26% accepted · 169 likes · top 4%
array · hash table · prefix sum
Description
You are given an integer array capacity.
A subarray capacity[l..r] is considered stable if:
- Its length is at least 3.
- The first and last elements are each equal to the sum of all elements strictly between them (i.e., capacity[l] = capacity[r] = capacity[l + 1] + capacity[l + 2] + ... + capacity[r - 1]).
Return an integer denoting the number of stable subarrays.
Solution