Binary Tree Problems for Coding Interviews
76 Binary Tree problems from real coding interviews, each with test cases you can run online. By difficulty they split into 27 basic, 40 intermediate and 9 advanced. The companies that ask them most often are Google, Amazon, Meta, Microsoft.
Solve a few problems of each level, name the pattern after each one and revisit the ones that needed a hint a week later. Practise stating the time and space complexity and the edge cases before you code.
Coding problems
- Count Unique Binary Search Trees (Basic)
- Count Downward Paths With Target Sum (Basic)
- Lowest Common Ancestor With Parent Pointers (Intermediate)
- Tree Infection Time (Intermediate)
- Tree Nodes at Distance K (Advanced)
- Maximum Weight Independent Set on Tree (Advanced)
- Minimum Dominating Set on Tree (Advanced)
- Tree Distance Queries (Basic)
- Tree Diameter (Advanced)
- BST Range Sum (Basic)
- BST Successor and Predecessor (Intermediate)
- Maximum Depth of Binary Tree (Basic)
- Balanced Binary Tree (Basic)
- Validate Binary Search Tree (Intermediate)
- Kth Smallest Value in a BST (Intermediate)
- Binary Tree Maximum Path Sum (Advanced)
- Count Good Nodes in Binary Tree (Intermediate)
- Binary Tree Right Side View (Intermediate)
- Binary Tree Inorder Traversal (Basic)
- Boundary of Binary Tree (Advanced)
- Invert Binary Tree (Basic)
- Binary Tree Preorder Traversal (Basic)
- Binary Tree Postorder Traversal (Basic)
- Level Sums of Binary Tree (Basic)
- Convert Sorted Array to BST (Basic)
- Tree From Preorder and Inorder (Intermediate)
- Tree From Inorder and Postorder (Intermediate)
- Binary Tree Tilt (Basic)
- Mode Values in a BST (Intermediate)
- Minimum Absolute Difference in BST (Basic)
- Two Sum in a BST (Basic)
- Trim a BST (Intermediate)
- Insert Into a BST (Basic)
- Delete Node in a BST (Intermediate)
- Recover Swapped BST Values (Intermediate)
- Maximum Width of Binary Tree (Intermediate)
- Cousins in Binary Tree (Basic)
- Univalued Binary Tree (Basic)
- Binary Tree Paths (Basic)
- Distribute Coins in Binary Tree (Intermediate)
- Flip Equivalent Binary Trees (Intermediate)
- Check Completeness of a Binary Tree (Intermediate)
- Minimum Depth of Binary Tree (Basic)
- Merge Two Binary Trees (Basic)
- Longest ZigZag Path in a Binary Tree (Intermediate)
- Maximum Product of Split Binary Tree (Intermediate)
- Closest Value in a BST (Basic)
- Binary Tree Coloring Game (Intermediate)
- Find Leaves of Binary Tree (Intermediate)
- BST From Preorder (Intermediate)
- Count Full Binary Trees (Intermediate)
- Maximum Sum BST in Binary Tree (Advanced)
- Ways to Reorder Array to Get Same BST (Advanced)
- Convert Sorted List to BST (Intermediate)
- Linked List in Binary Tree (Intermediate)
- Flatten Binary Tree to Linked List (Intermediate)
- Construct Maximum Binary Tree (Intermediate)
- Second Minimum Node in a Binary Tree (Basic)
- Construct String From Binary Tree (Basic)
- Binary Tree Upside Down (Intermediate)
- Increasing Order Search Tree (Basic)
- Convert BST to Greater Tree (Intermediate)
- Prune Binary Tree (Basic)
- Largest BST Subtree Size (Intermediate)
- Diagonal Traversal of Binary Tree (Intermediate)
- Top View of Binary Tree (Intermediate)
- Bottom View of Binary Tree (Intermediate)
- Check if Binary Tree Is a Heap (Intermediate)
- Balance a Binary Search Tree (Intermediate)
- Evaluate Boolean Binary Tree (Basic)
- Create Binary Tree From Descriptions (Intermediate)
- Cousins in Binary Tree II (Intermediate)
- Count Nodes With the Highest Score (Intermediate)
- Validate Binary Tree Nodes (Intermediate)
- Optimal Binary Search Tree Cost (Advanced)
- Minimum Cost Tree From Leaf Values (Intermediate)
Related
- Basic Binary Tree problems
- Intermediate Binary Tree problems
- Advanced Binary Tree problems
- Practice coding problems online
- All interview guides
Frequently asked questions
How do I get good at binary tree problems?
Practise by level, name the pattern after you solve each problem and review the ones you needed hints for. The list is ordered so you can start with the basic ones.
Can I run binary tree problems online here?
Yes. Each problem opens in an editor that runs your code against test cases in Java, Python, C++, Go, JavaScript and more.