m × n table grid: 1 is a free cell, 0 is blocked. A forklift starts at cell (0, 0) and has to reach (m - 1, n - 1); it can only move down or right, and only through free cells.
You may flip the value of at most one cell (1 to 0 or 0 to 1), except the start and the finish. Changing nothing is also allowed.
Return True if this way you can make the finish unreachable for the forklift, and False otherwise.grid=[[1, 1, 0], [0, 1, 1], [1, 1, 1]] → True
Every route passes through cell (0, 1): from the corner the only move is to the right, since below is a 0. Block it and no route is left.
grid=[[1, 1, 1], [1, 1, 1]] → False
Every inner cell can be bypassed by another route, so one blocked cell is not enough.
grid=[[1, 0], [0, 1]] → True
There is no route to begin with, so nothing has to change.
grid=[[1, 1, 0], [0, 1, 1], [1, 1, 1]]
True
Run checks the first 3 tests in your browser. Submit checks all 84 tests on the server, hidden ones included.