Problem of the day
Input: ‘N’ = 7, ‘K’ = 2, ‘A’ = [1, 0, 0, 0, 1, 0, 0]
Output: 1
It is possible to place locations 2 and 6 (0-indexed) the updated array will be [1, 0, 1, 0, 1, 0, 1] Here no two students are adjacent to each other.
The first line contains a single integer ‘T’ denoting the number of test cases, then the test case follows.
For each test case, the first line will contain two spaced integers ‘N’, the size of an input array ‘A’ and ‘K’. The second line will contain the ‘N’ spaced integers denoting the array ‘A’ values.
For each test case print, 1 if the Ninja is able to place that extra ‘K’ student else print 0.
Output for each test case will be printed on a separate line.
You are not required to print anything; it has already been taken care of. Just implement the function.
1 ≤ T ≤ 10
1 ≤ N ≤ 10^5
0 ≤ K ≤ 10^9
0 ≤ ‘A[i]’ ≤ 1
It is guaranteed that the sum of ‘N’ is ≤ 10^5 for all test cases.
Time limit: 1 sec
2
5 2
1 0 0 0 0
2 1
0 1
1
0
For test case 1:
It is possible to place at locations 2 and 4 (0-indexed) the updated array will be [1, 0, 1, 0, 1] Here no two students are adjacent to each other.
For test case 2:
For any possible combinations, there is no way to place the students.
2
4 1
1 1 1 1
2 1
0 0
0
1