← DoorDash Interview Insights

DoorDash·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
May 2026

Summary

DoorDash software engineer interview with a tree diffing problem that sounds deceptively manageable until you actually try to nail down all four change conditions cleanly. The parent-tracking piece is what trips people up.

Questions Asked (1)

Q1

Given two N-ary trees representing old and new versions of some structure, where each node has a string key, integer value, and list of children, write an algorithm to count how many nodes are considered 'changed'. A node is changed if it was deleted, added, has a different value for the same key, or has the same key and value but a different parent than before. Discuss time and space complexity.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

The deleted/added/value-changed cases came to me pretty fast.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the definition of 'changed' and the tree properties, then propose a two-pass approach: first traverse both trees to build a map from key to node metadata (value, parent key), then compare the maps to count added, deleted, and modified nodes. Analyze time and space complexity, noting that O(N) time and O(N) space is optimal for arbitrary trees.

Pro tip: Mention that if keys are unique, you can avoid storing the entire tree by using a hash map; if keys can duplicate, you need to handle collisions by including parent information in the key or using a multi-map. Also, consider iterative traversal to avoid stack overflow for deep trees.

1. Clarify requirements and assumptions

Ask whether keys are unique, whether node order among siblings matters, and confirm the definition of 'changed' (including parent change). Also clarify if the trees can be large and if recursion depth is a concern.

2. Choose traversal and data structures

Decide on a traversal method (BFS or DFS) and a data structure to store node information. A hash map from key to (value, parent key) is efficient if keys are unique; otherwise, use a composite key or a multi-map.

3. Traverse old tree and record metadata

Traverse the old tree, and for each node, record its key, value, and parent key (or null for root) in the chosen data structure. Count the total number of nodes in the old tree.

4. Traverse new tree and compare

Traverse the new tree. For each node, check if its key exists in the old tree's map. If not, it's added (count++). If it exists, compare value and parent key; if different, it's changed (count++). Mark the key as seen. After traversal, any keys in the old map not seen are deleted (count++).

5. Analyze complexity and edge cases

State that time complexity is O(N) where N is total number of nodes across both trees, and space complexity is O(N) for the hash map. Discuss edge cases: duplicate keys, root changes, deep trees (use iterative traversal), and memory constraints.

Key Points to Mention

  • Definition of 'changed' includes added, deleted, value change, and parent change.
  • Use a hash map to store key -> (value, parent key) for efficient lookup.
  • Handle duplicate keys by using a composite key (e.g., key + parent key) or a multi-map.
  • Time complexity O(N) and space complexity O(N) are optimal for this problem.
  • Consider iterative traversal (BFS/DFS with stack) to avoid recursion depth issues.
  • Edge cases: empty trees, single node, root parent change, and nodes with same key but different parents.

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