Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

BST Minimum

BSTeasy

Implement `bstMin(root)` returning the smallest value in a non-empty BST.

Sample tests

Input: bstMin({"val":5,"left":{"val":3,"left":null,"right":null},"right":{"val":8,"left":null,"right":null}})
Output: 3
Input: bstMin({"val":5,"left":null,"right":null})
Output: 5

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Scanning all nodes is unnecessary; follow left links.

Learning resources

  • Wikipedia: Binary search tree
Approach & explanation (try first)

In a BST the smallest value is the leftmost node, found in O(h).

Loading...
⌘/Ctrl + Enter

Run your code to see results.