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
Approach:
We will simply iterate over an array and check for each 0 whether the adjacent elements of it are 0 or not. If they are also 0 then we will increment the count.
If the total count is at least ‘K’ then we will print 1 else 0.
We need to handle the case for the first and last elements separately.
Algorithm: