← DoorDash Interview Insights

DoorDash·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

DoorDash software engineer interview with a tree problem that had a tricky follow-up, plus a design question thrown in. Pretty standard coding round but the follow-up on the tree problem is where things got interesting.

Questions Asked (2)

Q1

Given a binary tree, find the maximum distance between two 'alive' nodes, where alive nodes are initially defined as the leaves. Follow-up: generalize so that the set of alive nodes can be any arbitrary subset.

Algorithms & Data Structures
Author's notes

The base version is basically a diameter-of-tree problem restricted to leaves, which I'd seen before so I got through it okay.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the problem first: the maximum distance between two alive nodes is the diameter of the minimal subtree connecting all alive nodes. For the initial case where alive nodes are leaves, compute the tree's diameter using two BFS/DFS passes; for the follow-up, use a post-order traversal that tracks the deepest alive node in each subtree and combines depths at each node to find the maximum path.

Pro tip: Explicitly state that the problem reduces to finding the diameter of the minimal subtree spanning the alive nodes, and mention that the two-pass BFS approach works only for trees (not general graphs) and only when all alive nodes are leaves; for arbitrary subsets, a single post-order traversal is more efficient and handles all cases.

1. Clarify the problem and constraints

Ask whether the tree is binary, whether distances are measured in edges or nodes, and confirm that 'alive' nodes are initially leaves. For the follow-up, clarify that any subset of nodes can be alive.

2. Reduce to diameter of minimal subtree

Explain that the maximum distance between any two alive nodes is the diameter of the minimal subtree that connects all alive nodes. This subtree is formed by the union of paths between all pairs of alive nodes.

3. Solve initial case (alive = leaves)

For a tree where all leaves are alive, the diameter of the whole tree equals the maximum distance between leaves. Use two BFS/DFS passes: first from any node to find the farthest leaf, then from that leaf to find the farthest other leaf; the distance between them is the answer.

4. Generalize to arbitrary alive subset

Use a post-order traversal. For each node, compute the maximum depth to an alive node in its left and right subtrees. The longest path through the node is the sum of these depths (if both exist). Track the global maximum. Return the maximum depth to an alive node in the subtree (or -infinity if none).

5. Analyze complexity and edge cases

Time complexity is O(n) for both approaches; space is O(h) for recursion or O(n) for iterative. Handle edge cases: fewer than two alive nodes (return 0 or -1), tree with only one node, and alive nodes that are not leaves.

Key Points to Mention

  • The problem is equivalent to finding the diameter of the minimal subtree spanning all alive nodes.
  • For the initial case (alive = leaves), the two-pass BFS/DFS method works because the tree is acyclic and all leaves are alive.
  • For arbitrary alive subsets, a single post-order traversal that tracks the deepest alive node in each subtree is optimal.
  • At each node, the longest path through it is the sum of the maximum depths from its left and right subtrees (if both contain alive nodes).
  • Time complexity is O(n) and space complexity is O(h) for recursion, where h is the tree height.
  • Edge cases: fewer than two alive nodes, tree with a single node, and alive nodes that are not leaves.

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

Q2

Design a file system that supports creating paths and associating values with them.

System DesignAlgorithms & Data Structures
Author's notes

Trie question in disguise.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements: operations needed (create path, set/get value), path format, concurrency, and scale. Then propose a tree-based data structure where each node represents a path component and can store a value, and discuss how to handle edge cases like nested paths and overwrites.

Pro tip: Mention that this is essentially a trie with values at nodes, and that you can optimize for common operations like prefix queries or path compression. Also, proactively discuss trade-offs between in-memory and persistent storage, and how you'd handle concurrent access.

1. Clarify Requirements

Ask about expected operations (create, read, update, delete), path syntax (e.g., '/a/b/c'), whether values are strings or arbitrary, and concurrency/scale needs.

2. Design Data Structure

Propose a tree where each node has a map of child nodes and an optional value. Explain how to traverse and create nodes for each path component.

3. Implement Core Operations

Detail algorithms for createPath (split path, traverse/create nodes, set value) and get (traverse and return value). Discuss error handling for invalid paths.

4. Handle Edge Cases & Optimizations

Address overwriting existing values, deleting paths, and potential optimizations like path compression or caching frequently accessed paths.

5. Discuss Scalability & Concurrency

Talk about how to scale (sharding, persistent storage) and handle concurrent access (locks, transactions) if needed.

Key Points to Mention

  • Tree/trie data structure with nodes storing values
  • Path parsing and traversal (split by '/')
  • Time complexity: O(k) for k path components
  • Handling overwrites and deletions
  • Concurrency control (e.g., read-write locks)
  • Persistence and scalability considerations

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