Binary-tree

Level: Intermediate

1. Maximum Path Sum: Implement a function to find the maximum path sum in a binary tree.
2. Serialize and Deserialize: Write a function to serialize and deserialize a binary tree.
3. Kth Smallest Element: Implement a function to find the kth smallest element in a binary search tree (BST).
4. Kth Largest Element: Write a function to find the kth largest element in a BST.
5. Inorder Successor: Implement a function to find the inorder successor of a node in a BST.
6. Inorder Predecessor: Write a function to find the inorder predecessor of a node in a BST.
7. Build Tree from Inorder and Preorder: Implement a function to construct a binary tree from inorder and preorder traversals.
8. Build Tree from Inorder and Postorder: Write a function to construct a binary tree from inorder and postorder traversals.
9. Validate BST: Implement a function to check if a binary tree is a valid BST.
10. Convert BST to Greater Tree: Write a function to convert a BST to a greater tree.
11. Distance Between Nodes: Implement a function to find the distance between two nodes in a binary tree.
12. Nodes at Distance K: Write a function to find all nodes at a distance k from a given node in a binary tree.
13. LCA in BST: Implement a function to find the lowest common ancestor (LCA) of two nodes in a BST.
14. Maximum Width: Write a function to find the maximum width of a binary tree.
15. Vertical Sum: Implement a function to find the vertical sum of a binary tree.
16. Diagonal Sum: Write a function to find the diagonal sum of a binary tree.
17. Path Sum: Implement a function to check if a binary tree has a root-to-leaf path with a given sum.
18. Sum of Nodes with Even-Valued Grandparents: Write a function to find the sum of all nodes with even-valued grandparents in a binary tree.
19. Delete Node in BST: Implement a function to delete a node from a BST.
20. Insert Node in BST: Write a function to insert a node into a BST.
21. Sorted Array to BST: Implement a function to convert a sorted array to a BST.
22. Sorted Linked List to BST: Write a function to convert a sorted linked list to a BST.
23. Good Leaf Node Pairs: Implement a function to find the number of good leaf node pairs in a binary tree.
24. Sum of Nodes on Longest Path: Write a function to find the sum of nodes on the longest path from root to leaf in a binary tree.
25. Smallest Subtree with Deepest Nodes: Implement a function to find the smallest subtree with all the deepest nodes in a binary tree.
26. Recover BST: Write a function to recover a BST where two nodes are swapped by mistake.
27. Count Uni-value Subtrees: Implement a function to count the number of uni-value subtrees in a binary tree.
28. Sum of Nodes in Range: Write a function to find the sum of all nodes' values in a BST within a given range.
29. Deepest Leaves Sum: Implement a function to find the deepest leaves sum in a binary tree.
30. Check Height-Balanced Tree: Write a function to check if a binary tree is height-balanced.

Beginner Level: View

Advanced Level: View