Associated Course(s):
Must Do Interview Preparation

Given an array of 0's and 1's your task is to complete the function **maxLen** which returns size of the largest sub array with equal number of 0's and 1's. The function** maxLen** takes 2 arguments. The first argument is the array **A[]** and second argument is the size** 'N'** of the array **A[]**.

**Input:**

The first line of the input is** T** denoting the number of test cases. Then **T** test cases follow . Each test case contains two lines. The first line of each test case is a number **N** denoting the size of the array and in the next line are **N** space separated values of **A []**.

**Output:**

For each test case output in a new line the max length of the subarray.

**Constraints:**

1 <= T <= 100

1 <= N <= 100

0 <= A[] <= 1

**Example:
Input **

2

4

0 1 0 1

5

0 0 1 0 0

**Output**

4

2

**Explanation:
Testacase 1:** The array from index [0...3] contains equal number of 0's and 1's. Thus maximum length of subarray having equal number of 0's and 1's is 4.

Author: Shubham Joshi 1

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

makeitdonesolo | 320 |

Bishnu Dev Panda | 297 |

lost_found | 242 |

shubhamgaur_32 | 235 |

leo_messi | 229 |

Bishnu Dev Panda | 723 |

yk12 | 512 |

DevMittal | 472 |

okayboss | 456 |

VijethaShastri | 431 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4921 |

Quandray | 4547 |

Login to report an issue on this page.