
Asked in Expedia Group
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!
Add answer anonymously...
Top Software Developer Interview Questions Asked at Expedia Group
Q. Knight Probability in Chessboard Calculate the probability that a knight remains...read more
Q. Remove Character from String Problem Statement Given a string str and a characte...read more
Q. Binary Tree to Doubly Linked List Transform a given Binary Tree into a Doubly Li...read more
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Expedia Group Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
Stay ahead in your career. Get AmbitionBox app


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
AmbitionBox Awards
Get AmbitionBox app

