Walls and Gates
Given a m x n grid where -1 is a wall, 0 is a gate, and INF (2147483647) is an empty room. Fill each empty room with the distance to its nearest gate. If impossible to reach a gate, leave it as INF.
Walls and Gates

Given a m x n grid where -1 is a wall, 0 is a gate, and INF (2147483647) is an empty room. Fill each empty room with the distance to its nearest gate. If impossible to reach a gate, leave it as INF.

Example 1:
Input: {"rooms":[[2147483647,-1,0,2147483647],[2147483647,2147483647,2147483647,-1],[2147483647,-1,2147483647,-1],[0,-1,2147483647,2147483647]]}
Output: [[3,-1,0,1],[2,2,1,-1],[1,-1,2,-1],[0,-1,3,4]]
Input
arr ={"rooms":[[2147483647,-1,0,2147483647],[2147483647,2147483647,2147483647,-1],[2147483647,-1,2147483647,-1],[0,-1,2147483647,2147483647]]}

Initialize: Find all gates and add to queue

🧱
🚪
🧱
🧱
🧱
🚪
🧱
Gate (0)
Wall (-1)
Distance
In Queue
Variables
No variables to display
DepthFunction Call
Stack empty
0/11