Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding
Ninjas X Naukri.com

Problem of the day

Ninja has been asked to make the seating arrangement during the exam. Given an array ‘A’ of ‘N’ integers where ‘A[i] = 1’ means there is a student seated at the index ‘i’ and ‘A[i] = 0’ means that the place is currently unoccupied.

Provided no two students can seat adjacent to each other Ninjas has been asked to place extra ‘K’ students in the classroom.

Return 1 if the Ninja is able to place that extra ‘K’ student else return 0.

```
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.
```

Detailed explanation

```
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
```