Question bank › Arrays
Dsa Arrays Medium

Balanced Subarray

Given an array consisting of integers 1 and -1, find the length of the longest contiguous subarray that has a sum of zero. Output the length of this subarray. Input: - The first line contains an integer n, the number of elements in the array (1 ≤ n ≤ 100). - The second line consists of n space-separated integers (1 or -1). Output: - A single integer representing the length of the longest balanced subarray. Example: Input: 9 1 1 -1 -1 1 -1 1 -1 1 Output: 8

Key concepts

arrayssubarraysbalance

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.