Walls and Gates
MediumGraphs
Decode it first. Clues, constraints, pattern and plan before any code.A floor plan is a grid where -1 is a wall, 0 is a gate, and 2147483647 (call it INF) is an empty room. Fill every empty room with the number of steps to its nearest gate, moving up, down, left or right and never through walls. Rooms that cannot reach any gate keep INF. Change rooms in place; the function returns nothing.
INF -1 0 INF 3 -1 0 1
INF INF INF -1 → 2 2 1 -1
INF -1 INF -1 1 -1 2 -1
0 -1 INF INF 0 -1 3 4Constraints
1 <= rooms.length, rooms[i].length <= 250rooms[i][j]is-1,0or2147483647