Initialize a queue to store the positions of all gates in the grid.
Iterate over the grid to find all gates (cells with value 0) and add their positions to the queue.
Perform a BFS:
a. Dequeue a position from the queue.
b. Check all four adjacent cells (up, down, left, right).
c. If an adjacent cell is an empty room (INF), update its value with the current distance + 1 and enqueue its position.
d. If an adjacent cell is a wall or a gate, skip it.
Continue the BFS until the queue is empty.
Once the BFS is complete, all reachable empty rooms will have the shortest distance to a gate.