Problem Statement: Largest Subarray with Equal Number of 0s and 1s

Given an array containing only 0s and 1s, determine the length of the longest contiguous subarray that has an equal number of 0s and 1s.

Input:

int T
for each test case:
int N
int[] array

Output:

int - the length of the longest subarray with equal number of 0s and 1s for each test case.

Example:

Input:
[0, 0, 1, 0, 1]
Output:
4
Explanation:

The largest subarray is [0, 1, 0, 1] with a length of 4.

Constraints:

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 105
  • 0 ≤ Ai ≤ 1
  • Time Limit: 1 sec

Note:

No need to print the output. Just complete the function to return the result.

AnswerBot
4mo

Find the length of the longest subarray with equal number of 0s and 1s in a given array of 0s and 1s.

  • Iterate through the array and maintain a running count of the difference between the number of 0s a...read more

Help your peers!
Select
Add answer anonymously...

Expedia Group Software Developer interview questions & answers

A Software Developer was asked Q. Knight Probability in Chessboard Calculate the probability that a knight remains...read more
A Software Developer was asked Q. Remove Character from String Problem Statement Given a string str and a characte...read more
A Software Developer was asked Q. Binary Tree to Doubly Linked List Transform a given Binary Tree into a Doubly Li...read more

Popular interview questions of Software Developer

A Software Developer was asked Q1. Knight Probability in Chessboard Calculate the probability that a knight remains...read more
A Software Developer was asked Q2. Remove Character from String Problem Statement Given a string str and a characte...read more
A Software Developer was asked Q3. Binary Tree to Doubly Linked List Transform a given Binary Tree into a Doubly Li...read more
Expedia Group Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits