dsa2 min read
Construct Binary Search Tree from Preorder Traversal
Reconstruct a BST from its preorder traversal in O(n) using min-max bounds to place each node.
Read →
webcoderspeed.com
1276 articles
Reconstruct a BST from its preorder traversal in O(n) using min-max bounds to place each node.
Collect leaves by height (distance from leaf) repeatedly, returning all leaves at each height level.
Count nodes in a complete binary tree in O(log^2 n) by comparing left and right heights to identify full subtrees.
Find minimum seconds to collect all apples in a tree by DFS: include a subtree path only if it contains apples.
Find the maximum |a - b| for any ancestor-descendant pair by tracking min and max values along each root-to-leaf path.