Zero-Sum Subarrays
Count the contiguous subarrays whose elements sum to exactly zero.
Input: the first line has N; the second line has N integers.
Output: the number of zero-sum subarrays.
Constraints:
- 1 ≤ N ≤ 105
- −104 ≤ ai ≤ 104
Sample Tests
Input 1
6 3 -3 1 2 -3 4
Output 1
4
Input 2
3 0 0 0
Output 2
6
Discussion (opens after you solve — no spoilers before)
No comments yet.