Your question is Grid Traversal Function. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
In a Google DeepMind MuJoCo navigation simulation, an agent moves through a rectangular grid. Cells with value 0 are traversable, while cells with value 1 contain obstacles. Given the grid, a start coordinate, and a goal coordinate, return the minimum number of moves required to reach the goal. The agent may move up, down, left, or right, but not diagonally or through obstacles.
Return -1 if the goal cannot be reached. The start and goal cells are guaranteed to be traversable.
Implement shortest_path(grid, start, goal), where grid is a non-empty rectangular list of lists containing integers 0 or 1, and start and goal are coordinates represented as two-element lists [row, column]. Return an integer number of moves.
def shortest_path(grid, start, goal):