Advanced Tree Problems for Coding Interviews
37 advanced Tree problems from real coding interviews, each with test cases you can run online. By difficulty they split into 0 basic, 0 intermediate and 37 advanced. The companies that ask them most often are Amazon, Google, 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
- Tree Nodes at Distance K (Advanced)
- Maximum Weight Independent Set on Tree (Advanced)
- Minimum Dominating Set on Tree (Advanced)
- Tree Diameter (Advanced)
- N-ary Tree Diameter (Advanced)
- Binary Tree Maximum Path Sum (Advanced)
- Boundary of Binary Tree (Advanced)
- Tree Height After Subtree Removal Queries (Advanced)
- Maximum Sum BST in Binary Tree (Advanced)
- Sum of Distances in Tree (Advanced)
- Critical and Pseudo-Critical MST Edges (Advanced)
- Ways to Reorder Array to Get Same BST (Advanced)
- Maximum Path Sum Between Two Leaves (Advanced)
- Kth Ancestor Queries (Advanced)
- Redundant Directed Connection (Advanced)
- Second Best Minimum Spanning Tree (Advanced)
- Count Spanning Trees (Advanced)
- Cut Off Trees for Golf Event (Advanced)
- Number of Good Paths (Advanced)
- Collect Coins in a Tree (Advanced)
- Count Possible Root Nodes (Advanced)
- Max Min Price Sum Difference (Advanced)
- Count Prime Paths in a Tree (Advanced)
- Number of Ways to Reconstruct a Tree (Advanced)
- Tree of Coprimes (Advanced)
- Create Components With Same Value (Advanced)
- Optimal Binary Search Tree Cost (Advanced)
- LIS With Bounded Difference (Advanced)
- Farthest Node Distance for Every Node (Advanced)
- Path Cover Counts on Tree (Advanced)
- Are Two Rooted Trees Isomorphic (Advanced)
- Prufer Sequence of Labeled Tree (Advanced)
- Edges From Prufer Sequence (Advanced)
- Count Labeled Trees With Given Degrees (Advanced)
- Count Node Pairs at Distance K in Tree (Advanced)
- Count Descendants With Larger Value (Advanced)
- Green Hackenbush Tree Winner (Advanced)
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.