We have a sorted array. We can move between 2 consecutive elements if the difference is <= some int k. How can we determine efficiently in C if it is possible to move from a given index to the other?
For example, our sorted array is A[5]={1,3,5,8,20}. and K is given as 2. i.e. we can move between consecutive elements if and only if difference is < or = to K i.e. 2 in this case.
2 indices are given lets take index 0 and 3,i.e. A[0]=1 and A[3]=8. Now we can move from A[0] to A[1] iff A[1]-A[0] <=K, and so on upto A[3]. I have to do this process for multiple values of the indices, so I can be more efficient by storing the past results or something? If yes then how? Thank you.