Given a grid of rooms where -1 represents a wall, 0 represents a gate, and a large sentinel value represents an empty room, fill each empty room with the distance to its nearest gate. Leave rooms that can't reach a gate unchanged.
grid with a couple of gates and several empty roomseach empty room filled with its distance to the nearest gateSolve it in the editor. Sign in free to run your Python or JavaScript against test cases, get a verdict, and track your attempts.
Solve on FeatCode →A graph models relationships as nodes and edges, which can be directed or undirected, weighted or not. Most graph problems come down to choosing the right traversal — DFS, BFS, or union-find — for what you're trying to find.
Original problem on LeetCode ↗