Back to problems

Fill rooms with nearest-gate distance

Algorithm · Microsoft · Medium

A floor plan is represented as an integer grid with m rows and n columns. Each cell holds exactly one of these values: -1 denotes a wall or blocked cell. 0 denotes a gate. 2147483647 denotes an open room. For each open room, replace its value with the shortest distance needed to reach any gate. A move goes from a cell to one of its four adjacent cells: up, down, left, or right. You cannot enter a cell containing -1. If an open room cannot reach any gate, leave its value as…

Checking your access…