


You are given AIRPORTS = [1, 1, 1, 0, 1, 0], ‘K’ = 2 and ‘X’ = 4.
The answer will be 1. The plane makes its first stop at (2, 0) and then reaches the destination (4, 0) in the next fight. Hence the total number of stops is 1.
The first line contains an integer 'T' which denotes the number of test cases.
The first line of each test case contains three space-separated integers, ‘N’, ‘K’, ’X’, representing the length of the ‘AIRPORTS’ array, maximum distance covered by plane in one flight, and destination on the x-axis, respectively.
The second line of each test case contains N space-separated integers, representing the information about the airports on the x-axis.
For each test case, print a single integer, denoting the minimum number of stops that must be taken by the plane to reach the destination (X,0) on the x-axis.
The output of each test case will be printed in a separate line.
1 <= T <= 10
1 <= N <= 5000
1 <= K < N
1 <= X < N
0 <= AIRPORTS[i] <= 1
Time limit: 1 sec
You do not need to input or print anything, as it has already been taken care of. Just implement the given function.
In this approach, we will find the shortest path to the destination using Breadth-First Search. The starting point will be the origin, and all the airports at a distance at most ‘K’ from any airport ‘A’ will be considered the neighbors of ‘A’.
Algorithm:
In this approach, we will divide the problem into smaller sub-problems. We will define dp[i], which will store the minimum number of stops required to reach the destination from point i. Thus, dp[0] will be our final answer.
Algorithm:
In this approach, we will try to maintain a window of size of K. We will greedily open a window of size K and shrink it until we find an airport. If we did not found any airport, that means the destination is unreachable. We will continue opening the windows from the last stop until we reach the destination.
Algorithm: