Intermediate Tree Problems for Coding Interviews
95 intermediate Tree problems from real coding interviews, each with test cases you can run online. By difficulty they split into 0 basic, 95 intermediate and 0 advanced. The companies that ask them most often are Amazon, Google, Microsoft, Meta.
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
- Minimum Height Trees (Intermediate)
- Minimum Edge Reversals Per Node (Intermediate)
- Lowest Common Ancestor With Parent Pointers (Intermediate)
- Tree Infection Time (Intermediate)
- Tree Vertical Traversal (Intermediate)
- Dynamic Tree Value Updates (Intermediate)
- BST Successor and Predecessor (Intermediate)
- Root-to-Leaf Number Sum (Intermediate)
- Tree Path With Maximum Average (Intermediate)
- Validate Binary Search Tree (Intermediate)
- Kth Smallest Value in a BST (Intermediate)
- Count Good Nodes in Binary Tree (Intermediate)
- Binary Tree Right Side View (Intermediate)
- Zigzag Level Order Traversal (Intermediate)
- Lowest Common Ancestor of Two Values (Intermediate)
- Deepest Leaves Sum (Intermediate)
- Longest Univalue Path (Intermediate)
- Maximum Ancestor Difference (Intermediate)
- Subtree of Another Tree (Intermediate)
- Pseudo-Palindromic Root-to-Leaf Paths (Intermediate)
- Count Complete Tree Nodes (Intermediate)
- Tree From Preorder and Inorder (Intermediate)
- Tree From Inorder and Postorder (Intermediate)
- Mode Values in a BST (Intermediate)
- Trim a BST (Intermediate)
- Delete Node in a BST (Intermediate)
- Recover Swapped BST Values (Intermediate)
- Maximum Width of Binary Tree (Intermediate)
- Count Univalue Subtrees (Intermediate)
- Most Frequent Subtree Sum (Intermediate)
- Distribute Coins in Binary Tree (Intermediate)
- Flip Equivalent Binary Trees (Intermediate)
- Check Completeness of a Binary Tree (Intermediate)
- Smallest String Starting From Leaf (Intermediate)
- Even Odd Tree (Intermediate)
- Count Nodes Equal to Subtree Average (Intermediate)
- Longest ZigZag Path in a Binary Tree (Intermediate)
- Maximum Product of Split Binary Tree (Intermediate)
- Kth Largest Level Sum (Intermediate)
- Reverse Odd Levels of Perfect Tree (Intermediate)
- LCA of Deepest Leaves (Intermediate)
- Good Leaf Node Pairs (Intermediate)
- Binary Tree Coloring Game (Intermediate)
- Delete Leaves With a Given Value (Intermediate)
- Add One Row to Tree (Intermediate)
- Find Leaves of Binary Tree (Intermediate)
- BST From Preorder (Intermediate)
- Count Full Binary Trees (Intermediate)
- Directions Between Two Tree Nodes (Intermediate)
- Count Same-Label Nodes in Subtrees (Intermediate)
- Minimum Time to Collect All Apples (Intermediate)
- Graph Valid Tree (Intermediate)
- Redundant Connection (Intermediate)
- Maximum Number of Eaten Apples (Intermediate)
- Implement Trie Operations (Intermediate)
- Convert Sorted List to BST (Intermediate)
- Linked List in Binary Tree (Intermediate)
- Flatten Binary Tree to Linked List (Intermediate)
- Construct Maximum Binary Tree (Intermediate)
- Binary Tree Upside Down (Intermediate)
- Convert BST to Greater Tree (Intermediate)
- Insufficient Nodes in Root to Leaf Paths (Intermediate)
- Delete Nodes and Return Forest Sizes (Intermediate)
- 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)
- Merge Two BSTs Into Sorted Order (Intermediate)
- Balance a Binary Search Tree (Intermediate)
- Create Binary Tree From Descriptions (Intermediate)
- Cousins in Binary Tree II (Intermediate)
- Minimum Swaps to Sort Tree Levels (Intermediate)
- Find Elements in a Contaminated Tree (Intermediate)
- Longest Consecutive Parent-Child Sequence (Intermediate)
- Equal Tree Partition (Intermediate)
- Closest Leaf to a Target (Intermediate)
- Count Nodes With the Highest Score (Intermediate)
- Count Root-to-Leaf Paths With Distinct Values (Intermediate)
- Minimum Fuel Cost to the Capital (Intermediate)
Related
Frequently asked questions
How do I get good at 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 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.