The Light Problem
Submissions: 894   Accuracy:


  Difficulty: Easy   Marks: 2

There are N office cubicles placed in a straight line, each with a bright bulb. Each light bulb can brighten K rooms on either side of it (also the one in which the light bulb itself is), but all the cubicles don't have a bulb.
You are given an array A which gives the information about the location of the bulbs. If A[i] is equal to 1, then the cubicle has a light bulb, else if A[i] is 0, then the cubicle doesn't have a bulb.
You need to find out whether all the cubicles are bright or not.

Input : 
The first line of input contains a single integer T denoting the number of test cases.The first line of each test case contains 2 space-separated integers N and K.The second line contains N space-separated integers denoting the array A.

Output : 
For each test case, print "1" if all the cubicles are brightened, else "0" (without quotes " ") in a new line.

Constraints : 
1 <= T <= 100
1 <= N <= 500
1 <= K <= 20
0 <= A[i] <= 1

Example : 
Input : 

4 3
0 1 0 1
1 1
7 2
1 0 0 0 0 0 1
Output : 

Explanation : 
Case 1 : 

The first and third cubicles do not have bulbs.
Since K=3, first can be brightened by second and third can be brightened by fourth.

Case 2 : 
All cubicles have bulbs.

Case 3 : 
Since K=2, the second and third cubicle can be brightened by the first one, the fifth and sixth can be brightened by the seventh one.
But the fourth cubicle cannot be brightened by any of the bulbs, so the answer is 0.

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

Author: goyalanubhav11

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, generate link and share the link here.

to report an issue on this page.