← DoorDash Interview InsightsSoftware Engineer

DoorDash·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Oct 2026Remote

Summary

DoorDash phone screen for a software engineer role, one coding problem the whole time. Pretty smooth except for a small edge case fumble that I should have caught earlier.

Questions Asked (1)

Q1

Given a grid of 0s and 1s where 1s are source cells, return a matrix of the same size where each cell contains its shortest 4-directional distance to the nearest source cell. Source cells themselves have distance 0. If no source cells exist, return -1 for every cell.

Algorithms & Data Structures
Author's notes

Spotted multi-source BFS pretty fast, that part wasn't the issue.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use multi-source BFS starting from all source cells simultaneously, updating distances level by level. Initialize a distance matrix with -1 (or infinity) and set source cells to 0, then enqueue them. If no sources exist, return a matrix filled with -1.

Pro tip: Emphasize that multi-source BFS guarantees the shortest path in unweighted grids and runs in O(m*n) time, which is optimal. Also mention handling edge cases like empty grid or no sources early to avoid unnecessary work.

1. Clarify problem and edge cases

Confirm grid dimensions, 4-directional movement, and behavior when no sources exist. Discuss handling empty grid or all zeros.

2. Initialize data structures

Create a distance matrix filled with -1 (or a large number) and a queue. Iterate through the grid to set source cells to 0 and enqueue their coordinates.

3. Perform multi-source BFS

While the queue is not empty, pop a cell and explore its four neighbors. For each unvisited neighbor, set its distance to current distance + 1 and enqueue it.

4. Handle no-source case

If the queue is empty after initialization (no sources), return a matrix filled with -1 immediately.

5. Return result and analyze complexity

Return the distance matrix. State time complexity O(m*n) and space complexity O(m*n) for the queue and distance matrix.

Key Points to Mention

  • Multi-source BFS ensures shortest distances in unweighted grids
  • Time complexity O(m*n) where m and n are grid dimensions
  • Space complexity O(m*n) for queue and distance matrix
  • Handling edge cases: empty grid, no source cells, all source cells
  • Using a queue to process cells level by level
  • Avoiding revisiting cells by checking if distance is already set

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.