Longest Zero-Sum Subarray
Given an integer array nums, return the length of the longest non-empty contiguous subarray whose elements sum to 0. Return 0 when no such subarray exists.
Given an integer array `nums`, return the length of the longest non-empty contiguous subarray whose elements sum to `0`. Return `0` when no such subarray exists.
- `1 <= nums.length <= 2 * 10^4` - `-1000 <= nums[i] <= 1000` - The interactive visualizer accepts at most 12 values; longer statement-valid inputs are execution-only.
Example 1: input nums = [9,-3,3,-1,6,-5]; output 5. The subarray [-3,3,-1,6,-5] sums to 0 and has length 5.
Example 2: input nums = [1,2,3]; output 0. No non-empty contiguous subarray sums to 0.
Category: Arrays & Hashing. Topic: arrays. Difficulty: Medium. Patterns: hashing, prefix-sum.