Back to problems

Reconstruct a BST from Preorder Traversal

Algorithm · Lyft · Hard

A sequence preorder records the values encountered during a preorder traversal of a binary search tree. Every value in the sequence is distinct. Rebuild the exact BST represented by this traversal and return its root node. Assume a standard binary tree node type with an integer val, plus left and right child pointers. The input is guaranteed to be a valid preorder listing of a BST, so you do not need to validate it. Do not sort the values or rebalance the result; the…

Checking your access…