BETA

Difficulty Level:

Basic

Total Submissions: 4786 Accuracy:

18.55%

Fill array with 1's
       

Given an array of 0 and 1, in how many iterations the whole array be filled with 1's if in a single iteration immediate neighbours of 1's can be filled.

NOTE: If you cannot fill array with 1's then print "-1" .

Input:
The first line contains a single integer T i.e. the number of test cases. The first line consists of a single integer N(length of array) . The next line consists of a N spaced integers(either 0 or 1).

Output:
In one line print the minimum number of iterations to fill the whole string with 1's.

Constraints:
1<=T<=100
1<=N<=1000
0<=A[i]<=1

Examples:
Input:
2
15
1 0 1 0 0 1 0 1 1 0 1 1 0 0 1
17
0 0 1 1 0 0 1 1 0 1 1 1 1 0 0 0 1

Output:
1
2


Explanation:
Test Case 1:
To convert the whole array into 1's, one iteration is required . Between index i=2 and i=5 , the zero at i=3 would be converted to '1' due to its neighbour at i=2 similarly the zero at i=4 would be converted into '1' due to its neighbour at i=5 , all this can be done in a single iteration.     

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

Contributor: Saksham Ashtputre

Set Default Code

					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

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