Trees

Process a tree by solving each subtree and combining the results, using recursion for depth or a queue for levels. The tell is any hierarchy of nodes, as in Maximum Depth of Binary Tree and Binary Tree Level Order Traversal. Most answers come from one visit per node.

38 problems · 19 with a video · 3 to practice in an AI round

Trees problems
#ProblemDifficultyVideoAI round
1Lowest Common Ancestor of a Binary TreeMedium—AI round
2Validate Binary Search TreeMediumAI round
3Binary Tree Level Order TraversalMediumAI round
4Symmetric TreeEasy
5Construct Binary Tree from Preorder and Inorder TraversalMedium
6Diameter of Binary TreeEasy
7Invert Binary TreeEasy
8Binary Tree Inorder TraversalEasy
9Maximum Depth of Binary TreeEasy
10Binary Tree Right Side ViewMedium
11Same TreeEasy
12Kth Smallest Element in a BSTMedium—
13Lowest Common Ancestor of a Binary Search TreeMedium—
14Balanced Binary TreeEasy—
15All Nodes Distance K in Binary TreeMedium—
16Binary Tree Zigzag Level Order TraversalMedium
17Convert Sorted Array to Binary Search TreeEasy—
18Path Sum IIIMedium—
19Path SumEasy
20Delete Node in a BSTMedium—
21Maximum Width of Binary TreeMedium—
22Count Complete Tree NodesMedium
23Subtree of Another TreeEasy
24Binary Tree Preorder TraversalEasy
25Recover Binary Search TreeMedium—
26Minimum Depth of Binary TreeEasy
27Binary Tree Postorder TraversalEasy
28Range Sum of BSTVery easy
29Average of Levels in Binary TreeEasy
30Binary Tree Vertical Order TraversalMedium—
31Find Leaves of Binary TreeMedium—
32Inorder Successor in BSTMedium—
33Count Univalue SubtreesMedium—
34Binary Tree Longest Consecutive Sequence IIMedium—
35Binary Tree Longest Consecutive SequenceMedium—
36Kill ProcessMedium—
37Construct Binary Tree from StringMedium—
38Serialize and Deserialize N-ary TreeHard—

Practice in an AI round

Three of these are AI rounds: 30 minutes, an AI agent beside your code, then a scored report.

Practice Lowest Common Ancestor of a Binary Tree in an AI round