Closest Binary Search Tree Value

Easy · Binary Search Trees · about 10 minutes

Asked at Meta, Google, LinkedIn, Microsoft, Amazon.

Given the root of a non-empty binary search tree and a target value (a real number), return the value in the tree closest to target. If two values are equally close, return the smaller one.

Related guides