Confusion between dfs,bfs and dp

I have been trying this problem using dfs and memozing it but it is giving me wrong answer on one of the test cases. I have tried to run this against all trivial test cases but couldn’t figure out where i am going wrong.the link to the problem is
https://practice.geeksforgeeks.org/problems/steps-by-knight/0
and my solution code at coding blocks ide is


please help me where am i going wrong or what’s wrong with my logic

hello @Shobhit_kumar

dfs does not ensure minimum path,
use bfs algorithm for this problem.

refer this->article

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

sir you told me that u will get back to me with some eg to explain… do you find any counter eg??

@Shobhit_kumar

10
4 2
10 5

Its Correct output is:
3

And Your Code’s output is:
5

in this bali pairs question i have been trying the dp solution using map of <int,bool>to memoize my answer but it is showing run error?? can you plz tell where am i going wrong here is the link to my cb code… https://ide.codingblocks.com/s/350167

@Shobhit_kumar
pls create seprate thread (using ask doubt) for the problem that u r talking