Dsa
Sliding Window
Easy
Balanced Subarray with Zero Sum
Given an array of integers, your task is to find the length of the longest contiguous subarray that sums to zero. Return this length.
Input Format:
- The first line contains an integer `n`, the number of elements in the array.
- The second line contains `n` integers.
Output Format:
- Output the length of the longest subarray with zero sum as an integer.
Example:
Input:
5
1 -1 2 -2 3
Output:
4
Key concepts
sliding_windowarraypartition
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now