Minimum Toogles to partition
Submissions: 114   Accuracy:

39.49%

  Difficulty: Easy   Marks: 2

Given an array of n integers containing only 0 and 1. Write a program to find the minimum toggles (switch from 0 to 1 or vice-versa) required such the array the array become partitioned, i.e., it has first 0s then 1s. There should be at least one 0 in the beginning, and there can be zero or more 1s in the end.

Input:
First line of input contains a single integer T which denotes the number of test cases. Then T test cases follows. First line of each test case contains a single integer N which denotes the number of element in the array. Second line of each test case contains N space separated integers(0 or 1).

Output:
For each test case, print the minimum toggles (switch from 0 to 1 or vice-versa) required such the array the array become partitioned.

Constraints:
1<=T<=100
1<=N<=105

Example:
Input:

4
5
1 0 1 1 0
7
0 1 0 0 1 1 1
2
1 1
2
0 0
Output:
2
1
1
0

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Harsh Agarwal
Author: harsh.agarwal0


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.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.