Pattern
Trees
Most tree problems ask one question about a node and combine the answers from its children. Choose depth-first for questions about paths and shape, and breadth-first for questions about levels. The cost is usually O(n) time, with memory equal to the height.
1. Invert Binary Treetree · binary tree · stackEasy2. Maximum Depth of Binary Treetree · binary tree · bfsEasy3. Diameter of Binary Treetree · binary tree · heightEasy4. Balanced Binary Treetree · binary tree · heightEasy5. Same Treetree · binary tree · comparisonEasy6. Subtree of Another Treetree · binary tree · comparisonMed.7. Lowest Common Ancestor of a BSTtree · binary search tree · searchMed.8. Binary Tree Level Order Traversaltree · binary tree · bfsMed.9. Binary Tree Right Side Viewtree · binary tree · bfsMed.10. Count Good Nodes in Binary Treetree · binary tree · dfsMed.11. Validate Binary Search Treetree · binary tree · binary search tree · validationMed.12. Kth Smallest Element in a BSTtree · binary search tree · in-orderMed.13. Construct Binary Tree from Preorder and Inordertree · binary tree · traversalMed.14. Binary Tree Maximum Path Sumtree · binary tree · dynamic programmingHard15. Serialize and Deserialize Binary Treetree · binary tree · designHard