Faulty wiring and Bulbs
Submissions: 849   Accuracy:

27.36%

  Difficulty: Easy   Marks: 2

N light bulbs are connected by a wire. Each bulb has a switch associated with it, however due to faulty wiring, a switch also changes the state of all the bulbs to the right of current bulb. Given an initial state of all bulbs, find the minimum number of switches you have to press to turn on all the bulbs. "0 represents the bulb is off and 1 represents the bulb is on."

Input:
The first line of input contains an integer T denoting the number of test cases.Each test case consists of number of bulbs N and the next line consist of the space separated state of N bulbs.

Output:
Print the minimum number of press required to turn on all the bulbs.

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

Example:
Input:

2
4
0 0 0 0
4
1 0 0 1
Output:
1
2

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

Contributor: Shubham Chaudhary
Author: Shubham Chaudhary gfg


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.