Quant Memo
Coding/●●●●●

Shortest path through a grid with BFS

A robot in a warehouse grid must travel from start to goal. Cells marked 1 are blocked; moves are up/down/left/right, one cell per step.

grid = [[0, 0, 1],
        [0, 1, 0],
        [0, 0, 0]]
start = (0, 0), goal = (2, 2)
-> 4            # down, down, right, right

Return the minimum number of steps, or -1 if unreachable. Aim for O(nm)O(nm).

Your answer

This one is open-ended. Work it through, then check your reasoning against the full solution.

More Coding questions