I'm working on a problem where I'm trying to get from the top left corner, i.e. (0,0), to the bottom right, or (m - 1, n - 1), of an input m x n 2D array. Additionally, each element of the array represents what kind of jumps can be made from that square.
For example, a table that looks like:
1 2 1
1 1 1
1 1 1
Would have a minimum path of 3, since you can go from (0,0), jump 1 square right to (0,1), jump 2 squares down to (2, 1), then jump 1 square right to the destination of (2, 2).
My current implementation uses BFS, where I push each unvisited connected square into a queue, going through until I reach the corner or am unable to proceed; along the way, I update a seperate 2D array that contains the number of moves it takes to reach that particular coordinate on the actual board from the starting square.
My code works for many of the tests I throw at it, but for a few seemingly random test cases, it returns the wrong number of moves (higher than the actual number by quite a bit). I have no idea why this might be the case! Any suggestions on where I might have gone wrong would be really appreciated.