Skip to main content
Walls and Gates | AlgoCracked
AlgoCracked
ProblemsWalls and Gates
Medium60.0% acceptance
Blind75ArrayBfsMatrix

Walls and Gates

You are given an m x n grid rooms where each cell is one of three values: -1 marks a wall or obstacle, 0 marks a gate, and 2147483647 (that is 2^31 - 1) marks an empty room. Fill each empty room with the number of steps to its nearest gate, moving only up, down, left, or right. If an empty room cannot reach any gate, leave it as 2147483647 . Modify the grid in place . Input format The input is a single argument [rooms] , a JSON 2-D integer array, e.g. [[[2147483647,0]]] . The graded answer is the grid after your method mutates it; any value your method returns is ignored.

Loading workspace…