← DoorDash Interview Insights

DoorDash·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jun 2026Remote

Summary

DoorDash coding round, grid BFS problem with a follow-up on dynamic obstacle handling. Pretty domain-flavored but the core was standard multi-source BFS stuff. The follow-up is where things got interesting.

Questions Asked (2)

Q1

You have an m×n grid with store cells, home cells, road cells, and obstacle cells. For each home, find the shortest path distance to the nearest store. If no store is reachable from a home, return -1 for that home. Walk through your algorithm, its complexity, and write the code.

Algorithms & Data Structures
Author's notes

Multi-source BFS from all stores simultaneously, which gets you shortest distances to every reachable cell in one pass.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use multi-source BFS starting from all store cells simultaneously, treating the grid as an unweighted graph where each cell is a node connected to its 4-directional neighbors. Initialize distances to 0 for stores, infinity for others, and propagate level by level, skipping obstacles. After BFS, replace infinity with -1 for unreachable homes.

Pro tip: Emphasize that multi-source BFS is optimal because it computes all shortest paths in a single pass, avoiding repeated BFS from each home which would be inefficient. Also, mention that this approach naturally handles multiple stores and obstacles.

1. Clarify problem and constraints

Confirm grid dimensions, cell types (store, home, road, obstacle), movement allowed (4-directional), and that distance is number of steps. Ask about edge cases like no stores or no homes.

2. Choose algorithm and data structures

Select multi-source BFS using a queue. Use a 2D array for distances, initialized to -1 (unvisited) or infinity, and set store cells to 0. Use a queue to process cells level by level.

3. Implement BFS

Enqueue all store cells with distance 0. While queue not empty, dequeue a cell, and for each valid neighbor (within bounds, not obstacle, not visited), set distance = current distance + 1 and enqueue. This ensures shortest paths from any store.

4. Post-process and return result

After BFS, iterate over all home cells. If distance is still -1 (unvisited), set to -1 (unreachable). Otherwise, keep the computed distance. Return the grid or list of distances for homes as required.

5. Analyze complexity and test

State time complexity O(m*n) since each cell is visited at most once. Space complexity O(m*n) for the queue and distance array. Walk through a small example to verify correctness.

Key Points to Mention

  • Multi-source BFS treats all stores as sources at distance 0, ensuring shortest paths to any store.
  • Obstacles are skipped during neighbor exploration; they are never enqueued.
  • Distance array initialized to -1 (or infinity) to mark unvisited cells; stores set to 0.
  • Time complexity O(m*n) because each cell is processed once; space O(m*n) for queue and distance array.
  • Edge cases: no stores (all homes -1), no homes (return empty), stores unreachable due to obstacles.
  • Alternative approaches like Dijkstra 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.

Q2

If new obstacles are added to the grid frequently between queries, how would you update the shortest-path distances without running a full BFS from scratch each time?

Algorithms & Data StructuresTechnical Trade-offsSystem Design
Author's notes

I fumbled this pretty badly.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem constraints: grid size, frequency of obstacle additions, and query types (e.g., point-to-point or all-pairs). Then propose an incremental algorithm that updates distances only for affected regions, such as dynamic BFS or using a priority queue to propagate changes, and discuss trade-offs between time and space complexity.

Pro tip: Mention that if obstacles are only added (never removed), distances can only increase, so you can avoid recomputing unaffected areas. Also, consider preprocessing for common queries if the pattern is predictable.

1. Clarify constraints and assumptions

Ask about grid size, number of queries, frequency of obstacle additions, and whether obstacles can be removed. This determines the appropriate algorithm.

2. Identify affected regions

When an obstacle is added, only paths that previously went through that cell are affected. Use the previous distance map to identify cells whose shortest path might change.

3. Incremental update algorithm

Propose an algorithm like dynamic BFS: start from the new obstacle, update distances of neighbors, and propagate changes using a priority queue (similar to Dijkstra) until distances stabilize.

4. Analyze complexity and trade-offs

Compare the incremental approach (O(affected area)) with full BFS (O(V+E)). Discuss when full recomputation might be simpler or more efficient.

5. Consider optimizations and alternatives

Mention techniques like bidirectional BFS, A*, or preprocessing for frequent queries. If obstacles are added in batches, process them together.

Key Points to Mention

  • Dynamic BFS or incremental Dijkstra to update distances only where necessary
  • Use of a priority queue to propagate distance increases
  • Monotonicity: distances only increase when obstacles are added
  • Trade-off between update time and query time
  • Handling multiple obstacles efficiently (batch updates)
  • Applicability to DoorDash's delivery routing scenario (e.g., dynamic obstacles like traffic)

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