Back to problems

Shortest Distance to Taxi in a Grid

Algorithm · Google · Medium

You are given a two-dimensional grid containing multiple taxis. For every position, determine its minimum distance to the closest taxi. A taxi is denoted by 0, while an empty position is denoted by 1. Distance is measured by moving horizontally or vertically between neighboring cells. Examples Explanation: Each 0 is already at a taxi, and every other cell contains the fewest horizontal and vertical moves needed to reach either taxi. Explanation: Every entry is replaced with…

Checking your access…