Trees & BST problems, grouped by pattern
Trees are recursion with structure. Traversals come first, then postorder with multiple return values, LCA, views, serialization and the BST property. Most tree problems reduce to deciding what each call returns to its parent.
When to reach for it
- The input is a root node
- You need a value per level, per path or per subtree
- The tree is a BST and order matters
Mistakes to watch for
- Validating a BST using only the parent value
- Mixing up what a node returns vs what it records globally
- Forgetting null children in serialization
The 43 problems
1Recursion
- Binary Tree Inorder Traversal (Recursive) Animated Easy
- Binary Tree Preorder Traversal (Recursive) Animated Easy
- Binary Tree Postorder Traversal (Recursive) Animated Easy
- Binary Tree Inorder Traversal (Iterative) Animated Easy
- Binary Tree Preorder Traversal (Iterative) Animated Easy
- Binary Tree Postorder Traversal (Iterative) Animated Easy
- Maximum Depth of Binary Tree Animated Easy
- Same Tree Animated Easy
- Symmetric Tree Animated Easy
- Invert Binary Tree Animated Easy
2Backtracking
- Root to Leaf Paths Animated Medium
3Traversals
- Binary Tree Level Order Traversal Animated Medium
- Binary Tree Zigzag Level Order Traversal Animated Medium
- Binary Tree Level Order Traversal II Animated Medium
4Views
- Top View of Binary Tree Animated Medium
- Bottom View of Binary Tree Animated Medium
- Left View of Binary Tree Animated Easy
- Binary Tree Right Side View Animated Medium
5BST Basics
- Search in a Binary Search Tree Animated Easy
- Minimum element in BST Animated Easy
- Insert into a Binary Search Tree Animated Medium
6Postorder + Multiple Return Values
- Balanced Binary Tree Animated Easy
- Validate Binary Search Tree Animated Medium
- Children Sum in a Binary Tree Animated Easy
- Largest BST Animated Medium
7LCA
- Lowest Common Ancestor of a Binary Tree Animated Medium
- Lowest Common Ancestor of a Binary Search Tree Animated Medium
8Child + Ancestor Handling
- Amount of Time for Binary Tree to Be Infected Animated Medium
- Burning Tree Animated Hard
- All Nodes Distance K in Binary Tree Animated Medium
9Reverse Inorder Traversal
- Kth Smallest Element in a BST Animated Medium
- Kth Largest Element in BST Animated Easy
10Tree Serialization / Deserialization
- Construct Binary Tree from Preorder and Inorder Traversal Animated Medium
- Construct Binary Tree from Inorder and Postorder Traversal Animated Medium
- Construct Binary Search Tree from Preorder Traversal Animated Medium
- Serialize and Deserialize Binary Tree Animated Hard
11Tree to Lists and vice-versa
- Binary Tree to DLL Animated Hard
- Flatten Binary Tree to Linked List Animated Medium
12Miscellaneous BST Questions
- Inorder Successor in BST Animated Medium
- Inorder predecessor Animated Medium
- Floor in BST Animated Easy
- Ceil in BST Animated Easy
- Two Sum IV - Input is a BST Animated Easy