Blind 75 Tree Questions
11 problems · Free practice
Tree questions become manageable when each recursive call has one clearly defined job. Decide what a subtree returns to its parent and whether a separate answer must be updated along the way. Binary search trees add ordering constraints, while ordinary binary trees require reasoning from structure alone.
Practice trees
Invert Binary Tree
EasySwap the left and right children at every node of a binary tree and return its root. An empty tree stays empty.
Maximum Depth of Binary Tree
EasyFind the number of nodes on the longest path from a binary tree’s root down to a leaf. An empty tree has depth zero.
Same Tree
EasyDetermine whether two binary trees have identical structure and matching values at every corresponding node.
Subtree of Another Tree
EasyDetermine whether a nonempty binary tree subRoot appears as an entire subtree of root, with exactly the same node values and null-child structure.
Lowest Common Ancestor of a Binary Search Tree
MediumIn a BST with distinct values, find the lowest node whose subtree contains two given nodes p and q. A node may be its own ancestor; both targets exist.
Binary Tree Level Order Traversal
MediumReturn a binary tree’s values grouped by depth, from the root level downward and left to right within each level.
Validate Binary Search Tree
MediumDecide whether every node in a binary tree obeys strict BST ordering: all values in its left subtree are smaller, and all in its right subtree are larger.
Kth Smallest Element in a BST
MediumGiven a BST with distinct values and a valid one-based rank k, return its kth smallest value.
Construct Binary Tree From Preorder and Inorder Traversal
MediumRebuild a binary tree from valid preorder and inorder arrays containing the same distinct values. Return the root.
Binary Tree Maximum Path Sum
HardFind the largest sum along any nonempty path in a binary tree. A path follows parent-child edges without revisiting a node; it need not include the root.
Serialize and Deserialize Binary Tree
HardCreate a representation of a binary tree that can reconstruct both its values and exact shape. Support empty trees and negative values.
What to focus on
- State the result for a null subtree before handling a real node.
- For BST validation, carry ancestor bounds rather than comparing only parent and child.
- Distinguish a path that can extend to a parent from a complete path contained inside a subtree.