Distance to the Nearest Zero in a Binary Grid

Asked at Snowflake · Coding Questions · Difficulty: Medium · Last asked Dec 30, 2025

A grid of cells holds only `0` and `1`. For every cell, find how many steps it takes to reach the nearest cell containing `0`, moving one step at a time up, down, left or right. Return all of these distances as a grid of the same shape.

Loading the problem…