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<=10^{5}

**Example:
Input:**

4

5

1 0 1 1 0

7

0 1 0 0 1 1 1

2

1 1

2

0 0

2

1

1

0

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.

sabka_din_aayega | 342 |

maggiiiii | 262 |

Savage_19 | 226 |

thanuvinu94 | 211 |

lost_found | 173 |

Bishnu Dev Panda | 803 |

sabka_din_aayega | 653 |

Anugrah_kumar | 562 |

okayboss | 561 |

maggiiiii | 545 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4925 |

Quandray | 4547 |

Login to report an issue on this page.