Nearest Fire Station Distance for Every Residential Cell

Asked at LinkedIn · Coding Questions · Difficulty: Medium · Last asked Nov 10, 2026

A city is drawn as a rectangular grid. Some cells hold a fire station, some are lakes that nothing can cross, and the rest are residential cells. A fire truck drives one cell at a time to the cell directly above, below, left or right of it, and it can never enter a lake. For every residential cell, find how many moves the closest fire station is away.

Loading the problem…