Quant Memo
Coding/●●●●●

Counting grid paths around obstacles

Asked at Akuna Capital

A robot starts at the top-left cell of a grid and moves only right or down to reach the bottom-right cell. Some cells are blocked (marked 1) and cannot be entered.

grid = [[0, 0, 0],
        [0, 1, 0],
        [0, 0, 0]]
-> 2           # 1 = blocked; two clear paths remain

Return the number of distinct clear paths. Aim for O(nm)O(nm).

Show a hint

The number of ways to reach a cell is the number of ways to reach the cell above it plus the cell to its left. A blocked cell contributes zero ways.

Your answer

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

More Coding questions