PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/DoorDash

Find closest value to a target in a BST

Last updated: Mar 29, 2026

Quick Overview

This question evaluates understanding of binary search tree properties and numeric approximation, measuring competence in tree traversal, comparison logic, and algorithmic efficiency under input-size constraints.

  • medium
  • DoorDash
  • Coding & Algorithms
  • Machine Learning Engineer

Find closest value to a target in a BST

Company: DoorDash

Role: Machine Learning Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

## Problem Given the root of a **binary search tree (BST)** and a floating-point number `target`, return the **value in the BST that is closest to `target`**. If there are multiple values equally close, return the smaller value (or specify a deterministic tie-breaker). ## Input - `root`: root node of a BST (each node has `val`, `left`, `right`) - `target`: a real number ## Output - An integer value from the BST ## Constraints - Number of nodes: `1 .. 10^5` - Node values are integers in a reasonable range (e.g., 32-bit signed) - Tree may be unbalanced ## Example BST values: `[4,2,5,1,3]`, `target = 3.714286` → output `4`

Quick Answer: This question evaluates understanding of binary search tree properties and numeric approximation, measuring competence in tree traversal, comparison logic, and algorithmic efficiency under input-size constraints.

Related Interview Questions

  • Maximize Chef Assignment Profit - DoorDash (medium)
  • Compute Courier Delivery Pay - DoorDash (easy)
  • Compute Nearest Destination Distances - DoorDash (easy)
  • Compute Driver Pay with Double-Pay Windows - DoorDash (medium)
  • Count changed nodes between two menu trees - DoorDash (hard)
DoorDash logo
DoorDash
Oct 17, 2025, 12:00 AM
Machine Learning Engineer
Onsite
Coding & Algorithms
7
0

Problem

Given the root of a binary search tree (BST) and a floating-point number target, return the value in the BST that is closest to target.

If there are multiple values equally close, return the smaller value (or specify a deterministic tie-breaker).

Input

  • root : root node of a BST (each node has val , left , right )
  • target : a real number

Output

  • An integer value from the BST

Constraints

  • Number of nodes: 1 .. 10^5
  • Node values are integers in a reasonable range (e.g., 32-bit signed)
  • Tree may be unbalanced

Example

BST values: [4,2,5,1,3], target = 3.714286 → output 4

Submit Your Answer

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More DoorDash•More Machine Learning Engineer•DoorDash Machine Learning Engineer•DoorDash Coding & Algorithms•Machine Learning Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.