Minimum Toogles to partition
Easy Accuracy: 37.43% Submissions: 139 Points: 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  
1 <= A[] <= 100

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

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.