Problem
Longest Zero Sum Subarray
Learn this problemProblem statement
You are given an integer array nums containing positive and negative integers.
Return the length of the longest contiguous subarray whose sum is equal to 0. If no such subarray exists, return 0.
Function
longestZeroSumSubarray(nums: int[]) → intExamples
Example 1
nums = [15, -2, 2, -8, 1, 7, 10, 23]return = 5The subarray [-2, 2, -8, 1, 7] has sum 0 and length 5.
Example 2
nums = [1, 2, 3]return = 0No non-empty contiguous subarray has sum 0.
Constraints
1 <= nums.lengthnums[i]may be positive, negative, or zero.