Trees
Hierarchical nodes with parent–child links for ordered and nested data.
Trees Practice Problems
Easy
4 problems- 400easy
Invert Binary Tree
Swap every node’s two children so the tree becomes its own mirror image.
- 401easy
Same Tree
Walk two trees side by side and report whether they have the same shape and the same values.
- 402easy
Symmetric Tree
Check whether a tree folds onto itself by comparing mirror pairs from the two halves.
- 403easy
Balanced Binary Tree
Measure heights from the bottom up and check that no node has sides differing by more than one.
Medium
4 problems- 404medium
Binary Tree Right Side View
Walk the tree level by level and collect the last node of each level, the ones visible from the right.
- 405medium
Binary Tree Zigzag Level Order Traversal
Read the tree one level at a time, reversing every other level so the values snake down the tree.
- 406medium
Kth Smallest Element in a BST
Use the fact that an in-order walk of a binary search tree is already sorted, and stop at the kth value.
- 407medium
Lowest Common Ancestor of a Binary Tree
Let each node report whether it found either target below it, and the first node hearing from both sides wins.
Hard
2 problemsRelated concepts
| Topic | Description |
|---|---|
| Depth-First Search | Explore as far as possible down one path before backtracking, used to walk trees, graphs, and grids. |
| Breadth-First Search | Explore level by level from a starting point, the go-to way to find the shortest path in an unweighted graph. |
| Recursion | Solve a problem by having a function call itself on a smaller version of the same problem until it hits a base case. |
| Arrays | Ordered indexable collection for O(1) access by position. |
| Linked Lists | Nodes linked by pointers — insert and delete without shifting a contiguous block. |
| Stacks | Last-in, first-out collection for undo, parsing, and nested work. |