← DoorDash Interview Insights

DoorDash·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePass
May 2026

Summary

Passed a DoorDash coding round for a software engineer role. One problem, but it had a twist that made it more interesting than the usual BFS grid question.

Questions Asked (1)

Q1

You're given a 2D grid where some cells are obstacles and others are destinations. Find the shortest distance from every cell to its nearest destination. The catch: obstacle cells still need a valid distance computed, not just skipped.

Algorithms & Data Structures
Author's notes

The base BFS from all destination cells at once is pretty standard, but the obstacle wrinkle tripped me up initially.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use multi-source BFS starting from all destination cells simultaneously, treating obstacles as passable with a cost of 1. After computing distances, for each obstacle cell, find the minimum distance to any destination by considering its neighbors' distances plus one.

Pro tip: Clarify with the interviewer whether obstacles are passable for distance calculation; if not, you may need to compute distances through obstacles using a different method like Dijkstra with obstacles having a cost. Always discuss trade-offs and edge cases.

1. Understand the problem and constraints

Clarify that obstacles are passable for distance computation, and that distance is measured as the number of steps moving up/down/left/right. Confirm if diagonal moves are allowed.

2. Initialize multi-source BFS

Enqueue all destination cells with distance 0. Use a queue for BFS and a distance matrix initialized to infinity.

3. Run BFS treating obstacles as passable

During BFS, allow moving into obstacle cells as if they were normal cells, updating distances. This computes the shortest distance from each cell to the nearest destination, ignoring obstacles as barriers.

4. Post-process obstacle cells if needed

If the problem requires that obstacles are not passable, then after BFS, for each obstacle cell, compute its distance as 1 + min(neighbor distances) if any neighbor is reachable. Otherwise, mark as unreachable.

5. Return the distance matrix

Ensure all cells have a valid distance (or -1 if unreachable). Discuss time and space complexity: O(m*n) time and space.

Key Points to Mention

  • Multi-source BFS efficiently computes distances from multiple sources simultaneously.
  • Obstacles as passable vs. impassable changes the algorithm; clarify with interviewer.
  • Time complexity O(m*n) where m and n are grid dimensions.
  • Space complexity O(m*n) for the distance matrix and queue.
  • Edge cases: no destinations, all obstacles, unreachable cells.
  • Use of a queue for BFS and level-order traversal to ensure shortest paths.

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