Binary-tree

Level: Advanced

1. Largest BST Subtree: Implement a function to find the largest BST subtree in a binary tree.
2. Unique BSTs Count: Write a function to find the number of unique BSTs that can be formed with n nodes.
3. Min Swaps to Convert Tree to BST: Implement a function to find the minimum number of swaps required to convert a binary tree to a BST.
4. Max Sum BST in Binary Tree: Write a function to find the maximum sum BST in a binary tree.
5. Tree as Subtree: Implement a function to check if a binary tree is a subtree of another binary tree.
6. Smallest Subtree with Deepest Nodes: Write a function to find the smallest subtree with all the deepest nodes.
7. Largest Value in Each Level: Implement a function to find the largest value in each level of a binary tree.
8. Longest Consecutive Sequence Path: Write a function to find the longest consecutive sequence path in a binary tree.
9. Foldable Tree Check: Implement a function to check if a binary tree is foldable.
10. Sum of Nodes Under Binary Tree: Write a function to find the sum of all nodes under a binary tree.
11. Longest Path Between Nodes: Implement a function to find the largest distance between two nodes in a binary tree.
12. Max Product Path: Write a function to find the root-to-leaf path with the maximum product in a binary tree.
13. Paths with Given Sum: Implement a function to count the number of paths that sum to a given value in a binary tree.
14. Max XOR Between Nodes: Write a function to find the maximum XOR between two nodes in a binary tree.
15. Longest Bloodline Path Sum: Implement a function to find the sum of the longest bloodline path in a binary tree.
16. Max Average Subtree: Write a function to find the subtree with the maximum average in a binary tree.
17. Count Subtrees with Given Sum: Implement a function to find the number of subtrees having a given sum in a binary tree.
18. Longest Same Value Path: Write a function to find the length of the longest path in a binary tree with the same value.
19. Max Level Sum: Implement a function to find the maximum level sum in a binary tree.
20. Max Difference Between Node and Ancestor: Write a function to find the maximum difference between a node and its ancestor in a binary tree.
21. Count Non-Leaf Nodes: Implement a function to find the total number of non-leaf nodes in a binary tree.
22. Subtree with All Deepest Nodes: Write a function to find the subtree with all deepest nodes in a binary tree.
23. Closest Leaf Node: Implement a function to find the closest leaf node to a given node in a binary tree.
24. Count Nodes with Even-Valued Grandparents: Write a function to count the nodes in a binary tree with even-valued grandparents.
25. Minimum Swaps to Convert Binary Tree to BST: Implement a function to determine the minimum swaps to convert a binary tree to a BST.
26. Check Subtree: Write a function to check if a binary tree is a subtree of another binary tree.
27. BST with Maximum Sum: Implement a function to find the BST with the maximum sum in a binary tree.
28. Count Complete Tree Nodes: Write a function to count the nodes in a complete binary tree.
29. Longest Zigzag Path in Binary Tree: Implement a function to find the longest zigzag path in a binary tree.
30. Max Path Sum with At Most K Turns: Write a function to find the maximum path sum in a binary tree with at most k turns.

Beginner Level: View

Advanced Level: View