Traverse, build, compare, and validate binary trees and binary search trees.
Visit every node in a defined order
O(n)When to reach for it
Spot it in the prompt
Look for problems where you must visit each node systematically without missing any, often requiring recursion or iteration.
How to solve it
Animation: Traversal techniqueRecurse left, visit the node, then recurse right; iteratively simulate this with a stack pushing left children first.
Open full solutionRebuild trees from traversal sequences
When to reach for it
Spot it in the prompt
Explore problems where you must build a binary tree based on provided specifications, reconstructing it from its serialized form or given traversal sequences.
How to solve it
Animation: Construction techniqueTake the preorder head as root, locate it in inorder to split left and right subtrees, and recurse using an index map.
Open full solutionCompare or flip left and right subtrees
When to reach for it
Spot it in the prompt
Look for problems where you compare the left and right subtrees recursively or swap the left and right children to achieve symmetry.
How to solve it
Animation: Mirror & Symmetry techniqueRecursively swap left and right children at every node, or do it iteratively with a queue or stack.
Open full solutionTrack running sums along root-to-leaf paths
When to reach for it
Spot it in the prompt
Explore problems where you traverse the tree while keeping track of the path and its sum, recursively exploring all possible paths.
How to solve it
Animation: Path Sum & Root to Leaf techniqueDFS down the tree subtracting each node value from the target and check for zero at a leaf.
Open full solutionQuery trees using traversal and BST order
When to reach for it
Spot it in the prompt
Look for problems where you apply different traversal techniques or search algorithms specific to binary trees, such as inorder traversal or binary search.
How to solve it
Animation: Traversal & Search techniqueRecurse; if a node matches either target or its two subtrees both return non-null, that node is the LCA.
Open full solutionVerify structural properties of a tree
When to reach for it
Spot it in the prompt
Explore problems where you verify specific conditions or properties of binary trees, such as BST validation, balancedness checks, or identifying the diameter of the tree.
How to solve it
Animation: Validation & Properties techniqueCompute subtree heights via DFS while updating the max of left plus right height at each node.
Open full solutionFDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI