this question can be easily solved using RECURSION.

but can anyone please help me in finding the minimum number of steps to reach the (n,n) from (1,1) ?
i am struggling for it… please help me…thanks in advance!!!

1 Like
for the above code it is working when the ending point is (n,n) but if it is not (n,n) and the ending point is at the index where the value is 9.  then what changes should i change to the above code ? please help me....please.

This is really easy to do with Breadth First search. Just count one path for each edge you go through I guess.

how about printing dp[r][s] after calling above function ?

This question can be solved using simple Depth First Traversal which is a graph traversing algorithm.
Here is the debugged code. Hope this will help. click here

i need to find the minimum number of steps to reach the end point not the no. of different paths to reach…

can u plz tell me what wrong with this code ?? i need to find minimum no. of steps to reach ‘9’ and 9 may or may not locate at (n,n) !!

dp[r][s]=0 because min no. of steps to reach end point from end point (r,s) only.

it is giving correct output for some test cases … but some other cases showing output 0

A nicely designed BFS can work I guess, or Dijkstra’s