All topics
6 patterns · 28 problems

Binary Trees & BST

Traverse, build, compare, and validate binary trees and binary search trees.

01Pattern

Traversal

Visit every node in a defined order

This patternO(n)

When to reach for it

  • You need to visit each node in the tree exactly once, exploring all nodes in a specific order (e.g., inorder, preorder, postorder).

Spot it in the prompt

Look for problems where you must visit each node systematically without missing any, often requiring recursion or iteration.

Easy

Binary Tree Inorder Traversal

LeetCode
Loading animation…

How to solve it

Animation: Traversal technique

Recurse left, visit the node, then recurse right; iteratively simulate this with a stack pushing left children first.

Open full solution

Practice · 5 problems

Select any problem to watch the technique run. marks a problem with its own bespoke animation.

02Pattern

Construction

Rebuild trees from traversal sequences

When to reach for it

  • You need to create a binary tree from given input data, such as an array, inorder and preorder/postorder traversal sequences, or level order traversal.

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.

Medium

Construct Binary Tree from Preorder and Inorder Traversal

LeetCode
Loading animation…

How to solve it

Animation: Construction technique

Take the preorder head as root, locate it in inorder to split left and right subtrees, and recurse using an index map.

Open full solution

Practice · 3 problems

Select any problem to watch the technique run. marks a problem with its own bespoke animation.

03Pattern

Mirror & Symmetry

Compare or flip left and right subtrees

When to reach for it

  • You are tasked with determining whether a binary tree is symmetric or transforming it into its mirror image.

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.

Easy

Invert Binary Tree

LeetCode
Loading animation…

How to solve it

Animation: Mirror & Symmetry technique

Recursively swap left and right children at every node, or do it iteratively with a queue or stack.

Open full solution

Practice · 5 problems

Select any problem to watch the technique run. marks a problem with its own bespoke animation.

04Pattern

Path Sum & Root to Leaf

Track running sums along root-to-leaf paths

When to reach for it

  • You need to find paths in a binary tree that sum up to a target value or enumerate all root-to-leaf paths.

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.

Easy

Path Sum

LeetCode
Loading animation…

How to solve it

Animation: Path Sum & Root to Leaf technique

DFS down the tree subtracting each node value from the target and check for zero at a leaf.

Open full solution

Practice · 5 problems

Select any problem to watch the technique run. marks a problem with its own bespoke animation.

06Pattern

Validation & Properties

Verify structural properties of a tree

When to reach for it

  • You need to validate properties of a binary tree, such as whether it's a binary search tree or a balanced tree.

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.

Easy

Diameter of Binary Tree

LeetCode
Loading animation…

How to solve it

Animation: Validation & Properties technique

Compute subtree heights via DFS while updating the max of left plus right height at each node.

Open full solution

Practice · 5 problems

Select any problem to watch the technique run. marks a problem with its own bespoke animation.

You've got the patterns

Patterns get you through the screen. Shipping gets you hired.

FDE 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

August 15 · 0d left
Enroll Now