Approach This is a really interseting problem that I have not seen before, we can leverage the “binary lifting” to do efficient searching.
It is clear that we can sort the nums first, and when two values are reachable, we always walk to the farest node. For instance when we have 2,4,6,8, and max step is 3, we can only jump from 2->4->6->8 with 3 steps. For 2,4,6,8 with step 5, we can jump 2->6 since it is the maximum reachable node. I find that the maximum reachable tree can be construct in O(N) with two pointer teachqniue, but I did not figure out what is the best way to query from the tree. I was thinking that in the worse case, we would need to jump N times, and for q queriues, we would need O(qN).
...