Question statement : A plane can maximum cover a distance of k units. There are multiple airports on x- axis represented by 1 and if there are no airports it is represented by 0 . What is the minimum number of stops that must be taken by the plane to reach destination (x,0) on x-axis. Return -1 is the destination is unreachable. Start of plane [0,0] i.e. origin
example 1 :
k=5
destination =[4,0]
airports[1,0,1,1,1]
ans: 0
no stops required as plain can directly fly to (4,0)
example 2 :
k=5
destination= [8,0]
airports[1,0,0,0,0,0,0,1,1]
ans: -1
Plane can't reach point [8,0]
example 3:
k=3
destination= [8,0]
airports[1,0,0,1,1,1,1,1,1]
ans = 2
it requires 2 stops to reach (8,0)
Kindly provide what should be the best possible approch towards this question in JAVA.