visits in this order: the current node first, then its whole left subtree, then its whole right subtree (a preorder walk).
In a search tree, every value in a node's left subtree is strictly smaller than the node's value and every value in its right subtree is strictly larger. All values are distinct.
Rebuild the tree from the log and return its root. The log is guaranteed to come from some search tree.visits=[20, 11, 4, 15, 30, 25] → [20, 11, 30, 4, 15, 25]
The root is 20. The smaller values 11, 4, 15 go left: 11 with children 4 and 15. The larger 30, 25 go right: 30 with 25 as its left child.
visits=[9, 6, 3] → [9, 6, None, 3]
Each value is smaller than the last, so the tree is a chain going left.
visits=[500] → [500]
visits is the preorder walk of some search treevisits=[20, 11, 4, 15, 30, 25]
[20, 11, 30, 4, 15, 25]
Run checks the first 3 tests in your browser. Submit checks all 67 tests on the server, hidden ones included.