plan with m rows and n columns: 0 is a free cell and 1 is a wall that can be knocked down. You may move up, down, left or right, through free cells only.
You start at (0, 0) and want to reach (m - 1, n - 1). Return the fewest walls you must knock down to open such a path.plan=[[0, 1, 0], [0, 1, 0], [0, 1, 0]] → 1
The middle column is walled off from top to bottom, so one wall has to go, and one is enough.
plan=[[0, 0, 1], [1, 0, 1], [1, 0, 0]] → 0
The free cells (0, 0) → (0, 1) → (1, 1) → (2, 1) → (2, 2) form a path with nothing to break.
plan=[[0, 1, 1, 0]] → 2
A single-row corridor: both walls sit on the only route.
m, nm · n ≤ 10⁵plan[i][j] is 0 or 1plan[0][0] = plan[m - 1][n - 1] = 0plan=[[0, 1, 0], [0, 1, 0], [0, 1, 0]]
1
Run checks the first 3 tests in your browser. Submit checks all 60 tests on the server, hidden ones included.