Practice/Spotify/Leetcode 286. Walls and Gates
CodingMust
You are given a 2D grid representing a building layout with three types of cells:
2147483647 (INT_MAX)-1 (impassable walls)0 (doors leading outside)Your task is to modify the grid in-place so that each empty room contains the distance to its nearest exit point. The distance is measured as the minimum number of steps needed to reach an exit, where each step moves to an adjacent cell (up, down, left, or right). Barriers and exits should remain unchanged.
If an empty room cannot reach any exit point (blocked by barriers), it should remain as 2147483647.
021474836471 <= rooms.length, rooms[i].length <= 250rooms[i][j] is either -1, 0, or 21474836470 (at least one exit exists)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]]
Explanation:
Example 2:
` Input: rooms = [[2147483647, 2147483647], [2147483647, 0]]
Output: [[2, 1], [1, 0]]
Explanation: All rooms measure their distance from the single exit at the bottom-right corner. `
Example 3:
` Input: rooms = [[0]]
Output: [[0]]
Explanation: Single cell that is already an exit point. `