286. Walls and Gates

Problem

Fill each empty room with the distance to its nearest gate. Walls are -1, gates are 0, empty rooms are INF.

You are given a 2D grid where:

  • -1 represents a wall
  • 0 represents a gate
  • INF (represented as some large value like 2^31-1) represents an empty room

Fill each empty room (INF) with the distance to its nearest gate. If a room cannot reach a gate, leave it as INF.

Examples
Input: [[-1]]
Output: [[-1]]
Hints
Related Problems

286. Walls and Gates

Fill each empty room with the distance to its nearest gate. Walls are -1, gates are 0, empty rooms are INF.