← DiffPush

Minimum Value in a Binary Search Tree

Baseline Binary Search Trees · Concept O(h) · O(1)

The Leftmost Locker Rule

A parcel depot files consignments so smaller tracking numbers always sit to the left of larger ones. The receptionist hunting the smallest number in play never needs to open a single locker: she keeps turning left until a locker has no further left wing, and that dead-end locker holds the depot's minimum.

Input: A binary search tree as a level-order array (null marks a missing child).

Output: Return the minimum value stored in the tree.

Constraints

Examples

Example 1

Input: {"tree":[8,5,10,3,6,null,11]}
Output: 3
From 8, turning left twice reaches the leftmost locker 3.

Example 2

Input: {"tree":[10,5,15,null,7]}
Output: 5
5 has no left child, so it is already the smallest filed value.

Solve this in your browser →

Also on LeetCode ↗