Question bank › Arrays
Dsa Arrays Medium

Balanced Subarray Sum

You are given an array of integers. Your task is to determine the length of the longest contiguous subarray where the sum of the elements is equal to zero. If no such subarray exists, return 0. Input: - The first line contains an integer n (1 <= n <= 10^5), the number of elements in the array. - The second line contains n space-separated integers, the elements of the array. These integers can be both positive and negative. Output: - Print a single integer: the length of the longest subarray with a sum of zero. Example: Input: 8 1 2 -2 4 -4 1 1 -1 Output: 6

Key concepts

arraysprefix-sum

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.