Longest Zero Sum Subarray
MediumAsked in:Amazon•Stage:Onsite
Problem Statement
Given an integer array, find the length of the longest contiguous subarray whose elements sum to zero. If no such subarray exists, the answer is zero. The solution must run efficiently for large inputs.
Input Format
The first line contains an integer n (the size of the array). The second line contains n space‑separated integers arr[i].
Output Format
Print a single integer representing the maximum length of a zero‑sum subarray, or 0 if none exists.
Constraints
- 1 <= n <= 10^5
- -10^9 <= arr[i] <= 10^9