Trees & Binary Trees Interview Questions & Solutions
39 solutions ยท 18 Easy ยท 18 Medium ยท 3 Hard
Tree problems are where recursion finally clicks for most people. Almost every binary-tree question reduces to the same move: do something with the current node, then recurse on its left and right subtrees and combine the results. Once you internalize that "solve the node, trust the recursion for the children" rhythm, depth, path sums, symmetry, and traversal problems all start to look alike.
These solutions cover the full interview range: the four traversals (preorder, inorder, postorder, level-order) and when each matters, depth and balance checks, lowest common ancestor, path-sum variants, and binary search tree properties like ordered inorder traversal and validation. We're explicit about the two ways to carry information through a tree โ returning values up from children versus passing context down through parameters โ because knowing which one a problem needs is usually the whole battle. Master this set and you'll also be better prepared for graphs, since a tree is just a graph without cycles.
- Balanced Binary TreeEasy
- Binary Tree Inorder TraversalEasy
- Binary Tree Postorder TraversalEasy
- Binary Tree Preorder TraversalEasy
- Convert Sorted Array to Binary Search TreeEasy
- Diameter of Binary TreeEasy
- Invert Binary TreeEasy
- Leaf-Similar TreesEasy
- Lowest Common Ancestor of a Binary Search TreeEasy
- Maximum Depth of Binary TreeEasy
- Minimum Depth of Binary TreeEasy
- Minimum Distance Between BST NodesEasy
- Path SumEasy
- Same TreeEasy
- Search in a Binary Search TreeEasy
- Second Minimum Node In a Binary TreeEasy
- Subtree of Another TreeEasy
- Symmetric TreeEasy
- All Nodes Distance K in Binary TreeMedium
- Binary Tree Level Order TraversalMedium
- Binary Tree Right Side ViewMedium
- Binary Tree Zigzag Level Order TraversalMedium
- Construct Binary Tree from Inorder and Postorder TraversalMedium
- Construct Binary Tree from Preorder and Inorder TraversalMedium
- Delete Node in a BSTMedium
- Flatten Binary Tree to Linked ListMedium
- Kth Smallest Element in a BSTMedium
- Lowest Common Ancestor of a Binary TreeMedium
- Maximum Level Sum of a Binary TreeMedium
- Maximum Width of Binary TreeMedium
- Path Sum IIMedium
- Path Sum IIIMedium
- Recover Binary Search TreeMedium
- Step-By-Step Directions From a Binary Tree Node to AnotherMedium
- Sum of Nodes with Even-Valued GrandparentMedium
- Sum Root to Leaf NumbersMedium
- Binary Tree Maximum Path SumHard
- Sum of Distances in TreeHard
- Vertical Order Traversal of a Binary TreeHard
Practice Trees & Binary Trees the right way
SkillFlow serves you Trees & Binary Trees problems matched to your level, times you like a real interview, and tracks your proficiency as it climbs. Free.
Start practicing free โ