plan. Each cell holds one of three values:
- -1: a wall;
- 0: an exit;
- 2147483647: an empty room.
In one step you may move to a side-adjacent cell; you cannot pass through walls. Write into every empty room the number of steps to its nearest exit. If no exit can be reached, leave 2147483647 in the room.
Return the filled-in plan.plan=[[2147483647, 2147483647, 0], [-1, 2147483647, -1], [2147483647, 2147483647, 2147483647]] → [[2, 1, 0], [-1, 2, -1], [4, 3, 4]]
The answer is [[2, 1, 0], [-1, 2, -1], [4, 3, 4]].
plan=[[0, -1, 2147483647]] → [[0, -1, 2147483647]]
The right-hand room is cut off by a wall, so it keeps 2147483647: [[0, -1, 2147483647]].
plan=[[2147483647, 2147483647, 0], [-1, 2147483647, -1], [2147483647, 2147483647, 2147483647]]
[[2, 1, 0], [-1, 2, -1], [4, 3, 4]]
Run checks the first 3 tests in your browser. Submit checks all 34 tests on the server, hidden ones included.