Gold Mine Problem - GeeksforGeeks

Gold Mine Problem Method-1 Solve

I tried 2 methods - dp problem starting to solve from last column and continuing till the first column since in the problem it’s said that initial position is first column and end position is last column

The Link is below:

First code version loop ranging from (0,n-1) to (m-1,0) ie from top right corner to bottom left corner,
it is working fine

But it is not working for the second code version loop ranging from (m-1,n-1) to (0,0) ie from bottom right corner to top left corner.

Q1)Why second code failed to give correct results? What is my logic error?
Q2)How to know from similar problem from which corner point to which corner point to traverse?