Skip to content

Tree Problems

Tree problems test your ability to think recursively. From basic traversals (inorder, preorder, postorder) to more advanced operations like serialization, lowest common ancestor, and path sums.

47 problems

Title Difficulty
All Nodes Distance K in Binary Tree Medium
Balanced Binary Tree Easy
Binary Search Tree Iterator Medium
Binary Tree Cameras Hard
Binary Tree Level Order Traversal Medium
Binary Tree Maximum Path Sum Hard
Binary Tree Paths Easy
Binary Tree Right Side View Medium
Binary Tree Zigzag Level Order Traversal Medium
BST with a Dead End Easy
Construct Binary Tree from Preorder and Postorder Traversal Medium
Construct BST from Preorder Traversal Hard
Convert Sorted Array to Binary Search Tree Easy
Count BST Nodes in a Range Medium
Diameter of Binary Tree Easy
Median of a Binary Search Tree Hard
Flatten Binary Tree to Linked List Medium
Binary Tree Inorder Traversal Easy
Binary Tree to Doubly Linked List Hard
Invert Binary Tree Easy
Kth Smallest Element in a BST Medium
Largest BST Subtree Hard
Lowest Common Ancestor of a Binary Search Tree Easy
Lowest Common Ancestor of a Binary Tree Medium
Maximum Depth of Binary Tree Easy
Maximum Width of Binary Tree Medium
Merge Two Binary Trees Easy
Distance Between Two Tree Nodes Medium
Minimum Absolute Difference in BST Easy
Path Sum Easy
Path Sum III Medium
Populating Next Right Pointers in Each Node Medium
BST Predecessor and Successor Easy
Build a BST from Preorder Medium
All Downward Paths with Sum K Hard
Range Sum of BST Easy
Recover Binary Search Tree Medium
Same Tree Easy
Serialize and Deserialize Binary Tree Hard
Subtree of Another Tree Easy
Sum of Distances in Tree Hard
Sum of Left Leaves Easy
Symmetric Tree Easy
Unique Binary Search Trees Medium
Unique Binary Search Trees II Medium
Validate Binary Search Tree Medium
Vertical Order Traversal of a Binary Tree Hard