Given two coordinates A and B and a few valid movements, you have to determine whether you can move from A to B.

This is a familiar pattern to me. So, I tried to write a recursive solution with two exit conditions,

one is when the coordinates match in which case I return True.

But I can’t think of the exit condition where I am supposed to return False because the movement can be made to all 4 directions which makes it difficult to set constraints for the coordinate to be only within certain limits.

And even if we manage to find an exit condition for False, the solution seems to be exponential. Makes me wonder if the solution is just a formula and hence a O(1) solution.

I have been stuck on this since morning, please help. Thank you.