Trees line
Trees problems
A tree is nodes joined by links, each node with up to two children. Most answers come from a short recursive function that solves each child and combines the results.
- 6 easy
- 7 medium
- 2 hard
The 15 problems
In the order the app teaches them. Each page has the problem, five hints and the explained solution.
- Invert Binary TreeEasy
- Maximum Depth of Binary TreeEasy
- Diameter of Binary TreeEasy
- Balanced Binary TreeEasy
- Same TreeEasy
- Subtree of Another TreeEasy
- Lowest Common Ancestor of a Binary Search TreeMedium
- Binary Tree Level Order TraversalMedium
- Binary Tree Right Side ViewMedium
- Count Good Nodes In Binary TreeMedium
- Validate Binary Search TreeMedium
- Kth Smallest Element In a BstMedium
- Construct Binary Tree From Preorder And Inorder TraversalMedium
- Binary Tree Maximum Path SumHard
- Serialize And Deserialize Binary TreeHard
On the roadmap
Trees is a station on the trees line. It builds on Linked List. Next comes Tries and Backtracking.
The roadmap says why each line runs in its order.
Patterns
4 patterns solve these problems. Naming them gives the problems’ methods away, so the list is folded.
Show the 4
- Postorder tree recursion7 problems
- Binary search tree ordering2 problems
- Level-order tree traversal1 problem
- Preorder tree recursion5 problems