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.
Be the first one to answer
Add answer anonymously...
Top Expedia Group Software Developer interview questions & answers
Popular interview questions of Software Developer
>
Expedia Group Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app