Closest Binary Search Tree Value (LC 270)
Asked in the coding 2 stage. Given a binary search tree and a numeric target, return the value in the tree closest to the target. If two values are equally close, return the smaller value. Reported follow-up: Would anything change if node values were float?
The function receives root, represented as [value, left, right], with null for an empty child, and target. Return the closest numeric node value.
def closest_value(root, target):