LeetCodechevron_rightSolve patternschevron_rightbinary tree traversal
schemaReusable solving pattern

binary tree traversal Pattern

Pattern hubs are for building transferable solving frames. Learn the recognition signals first, then drill state definition, update rules, and edge explanation until the pattern feels stable.

database161 problemstune38/88/35 difficulty mixcategory6 linked topics

Pattern brief

Recognize first

Do you know why inorder on [1,null,2,3] must delay visiting 2 until after processing 3?

Solve rhythm

State the active state and invariant first, explain how each update preserves them, then pressure-test with counterexamples.

Most common miss

Appending a node value before fully traversing its left subtree, which turns the result into preorder-like output instead of inorder.

Recognition signals

  • Do you know why inorder on [1,null,2,3] must delay visiting 2 until after processing 3?
  • Can you explain how your traversal keeps track of where to return after finishing a left subtree?
  • Do you consider every integer as a potential root when generating BSTs?

Solve flow

  1. 1. Define the active state/window.
  2. 2. Update state while preserving invariants.
  3. 3. Validate with edge-heavy examples.

Common misses

  • Appending a node value before fully traversing its left subtree, which turns the result into preorder-like output instead of inorder.
  • Failing to combine all left and right subtree pairs for each root, leading to missing BSTs.
  • Not memoizing the results of subproblems, leading to redundant calculations.

Recommended Ladder

Problem bank

binary tree traversal pattern bank

Start by scanning with search or difficulty filters, then narrow by linked topics. The bank continues loading inside its own container so the page stays readable.

Progressive pattern bank

Use it to build pattern understanding first, then expand into the full corpus.

hourglass_bottomScroll inside to continue
search
tuneDifficulty
categoryTopic focus

Showing 24 / 161 problems

+24 per load
#TitleDifficulty
94

Binary Tree Inorder Traversal

Binary Tree Inorder Traversal asks you to visit left subtree, node, then right subtree without losing position while mov…

Easy
95

Unique Binary Search Trees II

Generate all structurally unique BSTs with values 1 to n using backtracking and recursive tree construction techniques.

Medium
96

Unique Binary Search Trees

Given n nodes, calculate the number of unique binary search trees (BSTs) that can be formed with values from 1 to n.

Medium
98

Validate Binary Search Tree

Validate Binary Search Tree problem checks if a binary tree satisfies BST properties using tree traversal and state trac…

Medium
99

Recover Binary Search Tree

Recover a BST where two nodes are swapped by mistake using in-order traversal and careful state tracking to restore corr…

Medium
100

Same Tree

Check whether two binary trees are identical by comparing structure and node values using DFS or BFS traversal strategie…

Easy
101

Symmetric Tree

Determine if a binary tree is symmetric by comparing left and right subtrees using DFS or BFS traversal techniques effic…

Easy
102

Binary Tree Level Order Traversal

Perform a level order traversal on a binary tree using BFS to return node values level by level.

Medium
103

Binary Tree Zigzag Level Order Traversal

Traverse a binary tree in zigzag level order, alternating directions at each depth using BFS and state tracking techniqu…

Medium
104

Maximum Depth of Binary Tree

Find the maximum depth of a binary tree using traversal techniques to track the longest path from root to leaf.

Easy
107

Binary Tree Level Order Traversal II

Return a bottom-up level order traversal of a binary tree, processing nodes left to right while tracking each level accu…

Medium
108

Convert Sorted Array to Binary Search Tree

Pick the middle element as root at each step so the sorted array becomes a height-balanced BST with valid ordering.

Easy
110

Balanced Binary Tree

Determine if a binary tree is height-balanced using tree traversal and state tracking techniques.

Easy
111

Minimum Depth of Binary Tree

Find the minimum depth of a binary tree, which is the shortest path from the root node to the nearest leaf node.

Easy
112

Path Sum

Determine if a binary tree has a root-to-leaf path where the sum of node values equals a given target sum, using DFS or …

Easy
113

Path Sum II

Find all root-to-leaf paths in a binary tree where the sum of node values equals a given target using DFS backtracking.

Medium
124

Binary Tree Maximum Path Sum

Calculate the maximum sum of any path in a binary tree by exploring all node sequences using DFS and dynamic programming…

Hard
129

Sum Root to Leaf Numbers

Calculate the sum of all root-to-leaf numbers in a binary tree where each path represents a number.

Medium
144

Binary Tree Preorder Traversal

Perform a binary tree preorder traversal by visiting root nodes first, then left and right subtrees, tracking state iter…

Easy
145

Binary Tree Postorder Traversal

Solve Binary Tree Postorder Traversal using state tracking and binary-tree traversal techniques, focusing on Stack, Tree…

Easy
173

Binary Search Tree Iterator

Implement an iterator for in-order traversal of a binary search tree (BST), maintaining traversal state with stack-based…

Medium
199

Binary Tree Right Side View

The Binary Tree Right Side View problem asks you to return the visible nodes from the right side of a binary tree, trave…

Medium
222

Count Complete Tree Nodes

Count Complete Tree Nodes efficiently by leveraging binary-tree traversal, exploiting completeness, and applying bit man…

Easy
226

Invert Binary Tree

Invert Binary Tree swaps every node's left and right children using tree traversal, with recursive DFS or iterative BFS …

Easy

swap_vertScroll inside the bank to auto-load more

Continue by topic

Once the pattern itself feels familiar, move back into concrete topic hubs so you can separate the pattern from the changing problem context.

route

Guided Practice Path

AI recommends problems by your level and tracks your progress.

Start Guided Patharrow_forward
Binary-tree traversal and state tracking LeetCode Pattern: 161 Solutions