Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

You are given an array consisting of 0s and 1s. You need to find the length of the largest subarray with an equal number of 0s and 1s.

For example:

```
If the given array is: [0, 0, 1, 0, 1] The largest subarray would be: [0, 1, 0, 1] (last 4 elements) having length 4.
```

Detailed explanation

```
The first line of input contains a single integer T, representing the number of test cases or queries to be run.
Then the T test cases follow.
The first line of each test case contains a single integer N denoting the length of the array.
The second line of each test case contains N space-separated integers representing the array elements.
```

```
For each test case, return the length of the largest subarray with the equal number of 0s and 1s, in a new line.
```

Note:

```
You are not required to print the expected output, it has already been taken care of. Just implement the function.
```

```
1 ≤ T ≤ 10
1 ≤ N ≤ 10^5
0 ≤ Ai ≤ 1
Time Limit : 1 sec
```

```
2
5
0 0 1 0 1
3
1 0 1
```

```
4
2
```

```
The first test case is already explained in the problem statement.
The second test case, the given array is: [1, 0, 1] The largest subarray would be: [1, 0] or [0,1].
```

```
2
3
1 1 1
5
0 0 0 1 1
```

```
0
4
```