Skip to content
core-pattern

Tree Depth-First Search

Define what each subtree returns upward or carries downward to solve traversal, validation, aggregation, and structural tree problems.

Problems

Problems in Tree Depth-First Search

Practice problems that share this primary solution pattern and compare the clues that reveal it.

Smartphone displaying AI app with book on AI technology in background.
beginner
10 min read

Binary Tree Inorder Traversal

The difficult part of inorder traversal is not remembering “left, node, right.” It is preserving the parent node while the left subtree is still…

View solution
Detailed view of a sewing machine needle stitching fabric, highlighting sewing process and textile technology.
advanced
12 min read

Recover Binary Search Tree

A binary search tree has a structural invariant that is more useful than its parent-child relationships: inorder traversal visits values in sorted order.…

View solution
Bright geometric pattern on a fence with green and white circles against a blue sky.
beginner
10 min read

Same Tree

A tree comparison fails the moment you forget that a missing child is also part of the structure.

View solution
Dynamic abstract image of vibrant green light trails in motion, creating a futuristic feel.
beginner
10 min read

Symmetric Tree

The key to the Symmetric Tree solution is to compare two nodes as a mirror pair, not to traverse the left and right subtrees independently.

View solution
Dynamic abstract depiction of digital circuits with vivid lights and glowing lines.
beginner
9 min read

Maximum Depth of Binary Tree

The cleanest way to solve this problem is to stop counting depth globally. Ask each subtree for its answer, then let the parent combine those answers.

View solution
Close-up of a craftsman using an angle grinder, emitting sparks in a metal workshop.
beginner
9 min read

Balanced Binary Tree

A reliable Balanced Binary Tree solution carries two facts upward from every subtree: its height and whether it is balanced.

View solution
A top view on charts and smartphone in an office, showcasing data analytics.
beginner
10 min read

Path Sum

A matching sum at an internal node is not enough. The path must start at the root, end at a leaf, and satisfy the target at that boundary.

View solution
Wide-angle view of a towering sand dune against a vibrant blue sky, showcasing the beauty of desert landscapes.
intermediate
10 min read

Path Sum II

That is the central trap in Path Sum II. An internal node may bring the running sum to targetSum, but its path is still incomplete if the node has a child.…

View solution