O11
Subarrays Sum to Zero
Problem Statement & Objective
Given an array of integers, find the total number of contiguous non-empty subarrays whose elements sum to exactly 0.
Function Signature (Python)
zero_sum_subarrays(nums: list[int]) -> intInput & Output Contract
Output Rule:Integer representing the count of zero-sum subarrays.
System Constraints
1 <= sayilar.length <= 10^5
-10^4 <= sayilar[i] <= 10^4Example Execution Walkthrough
sayilar = [1, -1, 1, -1]
prefix sums: [1, 0, 1, 0]
zero-sum subarrays: [1, -1], [-1, 1], [1, -1], [1, -1, 1, -1] -> result 4Example Test Scenarios (3)
Example 1
Input:
[[1,-1,2,-2,3]]Expected Output:
3Example 2: Üç Sıfır
Input:
[[0,0,0]]Expected Output:
6Example 3: Pozitif Dizi
Input:
[[1,2,3]]Expected Output:
0