Find Each Cell's Nearest Source

Quick Overview

This question evaluates understanding of shortest-path computation and distance labeling in grid-based graphs, measuring competency in algorithmic problem solving and efficient traversal strategies.

Find Each Cell's Nearest Source

Company: DoorDash

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Given an `m x n` grid containing `1` for source cells and `0` for regular cells, compute for every cell the shortest 4-directional distance to any source cell. Moving up, down, left, or right costs 1 step. Return an `m x n` matrix of distances, where every source cell has distance `0`. If the grid contains no source cells, return `-1` for every cell.

Quick Answer: This question evaluates understanding of shortest-path computation and distance labeling in grid-based graphs, measuring competency in algorithmic problem solving and efficient traversal strategies.

|Home/Coding & Algorithms/DoorDash
DoorDash logo
DoorDash
Feb 3, 2026, 12:00 AM
mediumSoftware EngineerOnsiteCoding & Algorithms
11
0

Given an m x n grid containing 1 for source cells and 0 for regular cells, compute for every cell the shortest 4-directional distance to any source cell. Moving up, down, left, or right costs 1 step. Return an m x n matrix of distances, where every source cell has distance 0. If the grid contains no source cells, return -1 for every cell.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...