← DoorDash Interview Insights

DoorDash·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
Jul 2026

Summary

DoorDash ML engineer screen, just one coding problem the whole time. Pretty straightforward BST question but the floating-point angle tripped me up for a second.

Questions Asked (1)

Q1

Given a binary search tree and a floating-point target value, find the node value in the tree that is closest to the target. If two values are equally close, return the smaller one.

Algorithms & Data Structures
Author's notes

The BST traversal part was fine, I've done that before.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Use the BST property to navigate from the root, keeping track of the closest value seen so far. At each node, compare the node's value to the target, update the closest if needed, and move left if the target is smaller or right if larger. Continue until reaching a null node, then return the closest value.

Pro tip: Explicitly handle the tie-breaking rule by preferring the smaller value when distances are equal, and mention that this approach runs in O(h) time where h is the tree height, which is efficient for balanced BSTs.

1. Clarify and Define

Confirm the BST property, the tie-breaking rule (smaller value wins), and that the tree may be empty or have duplicate values. Define 'closest' as minimal absolute difference.

2. Initialize Tracking

Set a variable to store the closest value found so far, initially the root's value (or None if tree is empty). Also set a pointer to the current node, starting at the root.

3. Iterative BST Traversal

While the current node is not null, compare its value to the target. Update the closest value if the current node is closer, or equally close but smaller. Then move left if target < node value, else move right.

4. Return Result

After the loop ends, return the closest value. If the tree was empty, return None or handle as appropriate.

5. Analyze Complexity

State that time complexity is O(h) where h is the height of the tree (O(log n) for balanced, O(n) worst-case), and space complexity is O(1) for iterative approach.

Key Points to Mention

  • Leveraging the BST property to prune search space (binary search-like traversal).
  • Maintaining the closest value and updating it based on absolute difference.
  • Tie-breaking logic: when distances are equal, choose the smaller value.
  • Handling edge cases: empty tree, single node, target outside the range of values.
  • Time and space complexity analysis: O(h) time, O(1) space for iterative solution.
  • Potential follow-up: how to handle duplicates or if the tree is not balanced.

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