← DoorDash Interview Insights

DoorDash·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Apr 2026

Summary

DoorDash technical screen focused on a grid-based shortest-path problem with a multi-source BFS twist. Pretty algorithmic, not much fluff around it.

Questions Asked (1)

Q1

Given a 2D grid with obstacles and multiple DashMart locations, find the shortest distance from every customer cell to its nearest DashMart. Explain your approach and why you'd choose multi-source BFS over running a separate BFS from each source.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

I knew BFS for shortest path on a grid, but the multi-source angle threw me a bit at first.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints (grid size, number of DashMarts, obstacles) and then propose a multi-source BFS from all DashMart locations simultaneously. Explain that this computes the shortest distance to the nearest DashMart for every cell in O(m*n) time, which is optimal, and contrast it with running BFS from each source which would be O(k*m*n) where k is the number of DashMarts.

Pro tip: Mention that multi-source BFS is equivalent to adding a virtual super-source connected to all DashMarts with zero-weight edges, which unifies the search and avoids redundant work. Also, note that if the grid is huge but DashMarts are few, a bidirectional BFS or A* might be considered, but multi-source BFS is simpler and often fast enough.

1. Clarify the problem and constraints

Ask about grid dimensions, number of DashMarts, obstacle representation, and whether distance is Manhattan or 4-directional. Confirm that we need distances from every cell to the nearest DashMart.

2. Propose multi-source BFS

Initialize a queue with all DashMart cells, set their distance to 0, and perform BFS level by level. For each cell, update its distance when first visited, ensuring the shortest path to any DashMart.

3. Analyze time and space complexity

Explain that multi-source BFS visits each cell at most once, giving O(m*n) time and O(m*n) space for the queue and distance grid. Compare with running BFS from each DashMart: O(k*m*n) time, which is inefficient when k is large.

4. Discuss trade-offs and alternatives

Mention that multi-source BFS is optimal for unweighted grids. If the grid is weighted, Dijkstra with multiple sources would be needed. Also, note that if only a few cells need distances, a different approach might be better.

5. Handle edge cases and implementation details

Address obstacles (skip them), unreachable cells (distance remains infinity), and multiple DashMarts in the same cell. Ensure the BFS explores only valid neighbors.

Key Points to Mention

  • Multi-source BFS initializes the queue with all sources, effectively computing the shortest distance from the nearest source in one pass.
  • Time complexity: O(m*n) for multi-source BFS vs O(k*m*n) for separate BFS from each of k sources.
  • Space complexity: O(m*n) for the distance grid and queue, which is optimal for storing distances to all cells.
  • Obstacles are treated as blocked cells and are not enqueued; unreachable cells get a distance of infinity.
  • The virtual super-source concept: adding a dummy node connected to all sources with zero-weight edges justifies the multi-source approach.
  • If the grid is weighted, use multi-source Dijkstra instead; multi-source BFS only works for unweighted graphs.

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