← DoorDash Interview Insights

DoorDash·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

Technical phone screen for a software engineer role at DoorDash. One coding problem, grid-based BFS stuff, felt pretty standard but there were enough wrinkles to trip you up if you weren't thinking carefully about the approach from the start.

Questions Asked (1)

Q1

Given a 2D grid with source cells and target cells (and possibly impassable walls), return a matrix where each cell contains the shortest 4-directional distance to the nearest source, or -1 if unreachable.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

My first instinct was to BFS from each source separately and merge results, which works but is painfully slow if there are many sources.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use multi-source BFS starting from all source cells simultaneously, treating the grid as an unweighted graph. Initialize a distance matrix with -1, set sources to 0, and enqueue them; then BFS level by level, updating distances for unvisited non-wall neighbors. This ensures each cell gets the shortest distance to any source in O(m*n) time.

Pro tip: Mention that multi-source BFS is equivalent to adding a virtual super-source connected to all sources, which elegantly handles the 'nearest' requirement and avoids redundant searches. Also, discuss how to handle edge cases like no sources or all walls.

1. Clarify problem and constraints

Confirm grid dimensions, movement directions (4-directional), and what constitutes a source, target, and wall. Ask about input size to discuss time/space complexity trade-offs.

2. Choose algorithm and data structures

Select multi-source BFS using a queue. Initialize a distance matrix with -1, set source cells to 0, and enqueue them. Use a queue for BFS and consider a visited set or rely on distance matrix.

3. Implement BFS traversal

While queue is not empty, dequeue a cell, explore its 4 neighbors. If a neighbor is within bounds, not a wall, and has distance -1, set its distance to current distance + 1 and enqueue it.

4. Handle unreachable cells and return result

After BFS, cells still at -1 are unreachable (or walls). Return the distance matrix, ensuring walls remain -1 or as specified.

5. Analyze complexity and edge cases

State time complexity O(m*n) since each cell is processed once, and space O(m*n) for the queue and distance matrix. Discuss edge cases: no sources, all walls, single cell, large grid.

Key Points to Mention

  • Multi-source BFS treats all sources as starting points simultaneously, ensuring shortest distance to nearest source.
  • Time complexity O(m*n) and space O(m*n) for the distance matrix and queue.
  • Use of a queue for BFS and a distance matrix initialized to -1.
  • Handling of walls (impassable) by not enqueueing them and leaving distance as -1.
  • Edge cases: no sources (all -1), sources unreachable to some cells, and grid boundaries.
  • Alternative approaches like Dijkstra's algorithm are unnecessary since all edges have unit weight; BFS is optimal.

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