Tree Traversal Pattern: Template + 225 LeetCode Problems

Choose the order — preorder, inorder, postorder, level — and the problem solves itself.

  • 41 Easy
  • 142 Medium
  • 42 Hard
  • O(n) time

What the tree traversal pattern is

Almost every binary tree problem is a traversal with a small amount of work attached, so the real decision is when the node gets processed relative to its children. Preorder handles a node before descending and is what you want for copying, serialising, or passing information down from the root. Postorder handles it after both children return and is what you want whenever the answer at a node is computed from its subtrees — heights, diameters, subtree sums, the maximum path sum. Inorder is the special one: on a binary search tree it emits the values in sorted order, which turns validation, the kth smallest, and finding the minimum gap into a single scan with a pointer to the previously visited value. Level order is breadth-first search on a tree, done by draining the queue one full level at a time so each level can be handled as a unit. The iterative inorder is the traversal worth being able to write from memory, because it is the one an interviewer will ask for when recursion is ruled out.

When to use it

  • A value at each node depends on its subtrees — that is postorder.
  • The tree is a BST and the question is about sorted order, a kth element, or a range.
  • The answer is per level, or is the shallowest node satisfying a condition.
  • You are asked to serialise, clone, or rebuild a tree from traversal output.

The tree traversal template in Python

The shape, not a solution to any one problem. Adapt the condition and the summary being maintained; the skeleton stays the same across the 225 problems listed below.

Tree Traversal — Python template
def inorder(root):
    result, stack, node = [], [], root

    while node or stack:
        while node:                  # descend as far left as possible
            stack.append(node)
            node = node.left

        node = stack.pop()
        result.append(node.val)      # left subtree finished, so visit now
        node = node.right            # then do the same for the right subtree

    return result

Complexity characteristics

Time
O(n)
Auxiliary space
O(h), where h is the height of the tree

Every node is visited exactly once whatever the order, so the time is linear in the node count. The space is the recursion stack or the explicit stack, which is the height of the tree: O(log n) on a balanced tree and O(n) on a degenerate one, and the degenerate one is what a test harness will hand you. Level-order traversal swaps the stack for a queue holding the widest level, which is up to n/2 nodes on a full tree.

All 225 tree traversal LeetCode problems

Every problem in the library the tree traversal pattern applies to, grouped by LeetCode's own difficulty rating. 167 of the 225 carry a complete Python solution with a worked example and complexity analysis; the rest are listed for completeness, with the LeetCode Premium ones marked.

Easy (41)

#ProblemDifficultyTopics
94Binary Tree Inorder TraversalEasyStack, Tree, Depth-First Search +1
100Same TreeEasyTree, Depth-First Search, Breadth-First Search +1
101Symmetric TreeEasyTree, Depth-First Search, Breadth-First Search +1
104Maximum Depth of Binary TreeEasyTree, Depth-First Search, Breadth-First Search +1
108Convert Sorted Array to Binary Search TreeEasyTree, Binary Search Tree, Array +2
110Balanced Binary TreeEasyTree, Depth-First Search, Binary Tree
111Minimum Depth of Binary TreeEasyTree, Depth-First Search, Breadth-First Search +1
112Path SumEasyTree, Depth-First Search, Breadth-First Search +1
144Binary Tree Preorder TraversalEasyStack, Tree, Depth-First Search +1
145Binary Tree Postorder TraversalEasyStack, Tree, Depth-First Search +1
222Count Complete Tree NodesEasyBit Manipulation, Tree, Binary Search +1
226Invert Binary TreeEasyTree, Depth-First Search, Breadth-First Search +1
257Binary Tree PathsEasyTree, Depth-First Search, String +2
404Sum of Left LeavesEasyTree, Depth-First Search, Breadth-First Search +1
501Find Mode in Binary Search TreeEasyTree, Depth-First Search, Binary Search Tree +1
530Minimum Absolute Difference in BSTEasyTree, Depth-First Search, Breadth-First Search +2
543Diameter of Binary TreeEasyTree, Depth-First Search, Binary Tree
559Maximum Depth of N-ary TreeEasyTree, Depth-First Search, Breadth-First Search
563Binary Tree TiltEasyTree, Depth-First Search, Binary Tree
572Subtree of Another TreeEasyTree, Depth-First Search, Binary Tree +2
589N-ary Tree Preorder TraversalEasyStack, Tree, Depth-First Search
590N-ary Tree Postorder TraversalEasyStack, Tree, Depth-First Search
617Merge Two Binary TreesEasyTree, Depth-First Search, Breadth-First Search +1
637Average of Levels in Binary TreeEasyTree, Depth-First Search, Breadth-First Search +1
653Two Sum IV - Input is a BSTEasyTree, Depth-First Search, Breadth-First Search +4
671Second Minimum Node In a Binary TreeEasyTree, Depth-First Search, Binary Tree
700Search in a Binary Search TreeEasyTree, Binary Search Tree, Binary Tree
703Kth Largest Element in a StreamEasyTree, Design, Binary Search Tree +3
872Leaf-Similar TreesEasyTree, Depth-First Search, Binary Tree
270Closest Binary Search Tree ValuePremiumEasyTree, Depth-First Search, Binary Search Tree +2
783Minimum Distance Between BST NodesEasyTree, Depth-First Search, Breadth-First Search +2
897Increasing Order Search TreeEasyStack, Tree, Depth-First Search +2
938Range Sum of BSTEasyTree, Depth-First Search, Binary Search Tree +1
965Univalued Binary TreeEasyTree, Depth-First Search, Breadth-First Search +1
993Cousins in Binary TreeEasyTree, Depth-First Search, Breadth-First Search +1
1022Sum of Root To Leaf Binary NumbersEasyTree, Depth-First Search, Binary Tree
1379Find a Corresponding Node of a Binary Tree in a Clone of That TreeEasyTree, Depth-First Search, Breadth-First Search +1
1469Find All The Lonely NodesPremiumEasyTree, Depth-First Search, Breadth-First Search +1
2236Root Equals Sum of ChildrenEasyTree, Binary Tree
2331Evaluate Boolean Binary TreeEasyTree, Depth-First Search, Binary Tree
2689Extract Kth Character From The Rope TreePremiumEasyTree, Depth-First Search, Binary Tree

Medium (142)

#ProblemDifficultyTopics
95Unique Binary Search Trees IIMediumTree, Binary Search Tree, Dynamic Programming +2
96Unique Binary Search TreesMediumTree, Binary Search Tree, Math +2
98Validate Binary Search TreeMediumTree, Depth-First Search, Binary Search Tree +1
99Recover Binary Search TreeMediumTree, Depth-First Search, Binary Search Tree +1
102Binary Tree Level Order TraversalMediumTree, Breadth-First Search, Binary Tree
103Binary Tree Zigzag Level Order TraversalMediumTree, Breadth-First Search, Binary Tree
105Construct Binary Tree from Preorder and Inorder TraversalMediumTree, Array, Hash Table +2
106Construct Binary Tree from Inorder and Postorder TraversalMediumTree, Array, Hash Table +2
107Binary Tree Level Order Traversal IIMediumTree, Breadth-First Search, Binary Tree
109Convert Sorted List to Binary Search TreeMediumTree, Binary Search Tree, Linked List +2
113Path Sum IIMediumTree, Depth-First Search, Backtracking +1
114Flatten Binary Tree to Linked ListMediumStack, Tree, Depth-First Search +2
116Populating Next Right Pointers in Each NodeMediumTree, Depth-First Search, Breadth-First Search +2
117Populating Next Right Pointers in Each Node IIMediumTree, Depth-First Search, Breadth-First Search +2
129Sum Root to Leaf NumbersMediumTree, Depth-First Search, Binary Tree
173Binary Search Tree IteratorMediumStack, Tree, Design +3
199Binary Tree Right Side ViewMediumTree, Depth-First Search, Breadth-First Search +1
230Kth Smallest Element in a BSTMediumTree, Depth-First Search, Binary Search Tree +1
235Lowest Common Ancestor of a Binary Search TreeMediumTree, Depth-First Search, Binary Search Tree +1
236Lowest Common Ancestor of a Binary TreeMediumTree, Depth-First Search, Binary Tree
331Verify Preorder Serialization of a Binary TreeMediumStack, Tree, String +1
337House Robber IIIMediumTree, Depth-First Search, Dynamic Programming +1
341Flatten Nested List IteratorMediumStack, Tree, Depth-First Search +3
427Construct Quad TreeMediumTree, Array, Divide and Conquer +1
429N-ary Tree Level Order TraversalMediumTree, Breadth-First Search
437Path Sum IIIMediumTree, Depth-First Search, Binary Tree
449Serialize and Deserialize BSTMediumTree, Depth-First Search, Breadth-First Search +4
450Delete Node in a BSTMediumTree, Binary Search Tree, Binary Tree
508Most Frequent Subtree SumMediumTree, Depth-First Search, Hash Table +1
513Find Bottom Left Tree ValueMediumTree, Depth-First Search, Breadth-First Search +1
515Find Largest Value in Each Tree RowMediumTree, Depth-First Search, Breadth-First Search +1
538Convert BST to Greater TreeMediumTree, Depth-First Search, Binary Search Tree +1
558Logical OR of Two Binary Grids Represented as Quad-TreesMediumTree, Divide and Conquer
606Construct String from Binary TreeMediumTree, Depth-First Search, String +1
623Add One Row to TreeMediumTree, Depth-First Search, Breadth-First Search +1
652Find Duplicate SubtreesMediumTree, Depth-First Search, Hash Table +1
654Maximum Binary TreeMediumStack, Tree, Array +3
655Print Binary TreeMediumTree, Depth-First Search, Breadth-First Search +1
662Maximum Width of Binary TreeMediumTree, Depth-First Search, Breadth-First Search +1
669Trim a Binary Search TreeMediumTree, Depth-First Search, Binary Search Tree +1
687Longest Univalue PathMediumTree, Depth-First Search, Binary Tree
690Employee ImportanceMediumTree, Depth-First Search, Breadth-First Search +2
701Insert into a Binary Search TreeMediumTree, Binary Search Tree, Binary Tree
1161Maximum Level Sum of a Binary TreeMediumTree, Depth-First Search, Breadth-First Search +1
1372Longest ZigZag Path in a Binary TreeMediumTree, Depth-First Search, Dynamic Programming +1
1448Count Good Nodes in Binary TreeMediumTree, Depth-First Search, Breadth-First Search +1
156Binary Tree Upside DownPremiumMediumTree, Depth-First Search, Binary Tree
250Count Univalue SubtreesPremiumMediumTree, Depth-First Search, Binary Tree
255Verify Preorder Sequence in Binary Search TreePremiumMediumStack, Tree, Binary Search Tree +4
285Inorder Successor in BSTPremiumMediumTree, Depth-First Search, Binary Search Tree +1
298Binary Tree Longest Consecutive SequencePremiumMediumTree, Depth-First Search, Binary Tree
314Binary Tree Vertical Order TraversalPremiumMediumTree, Depth-First Search, Breadth-First Search +3
333Largest BST SubtreePremiumMediumTree, Depth-First Search, Binary Search Tree +2
366Find Leaves of Binary TreePremiumMediumTree, Depth-First Search, Binary Tree
426Convert Binary Search Tree to Sorted Doubly Linked ListPremiumMediumStack, Tree, Depth-First Search +4
510Inorder Successor in BST IIPremiumMediumTree, Binary Search Tree, Binary Tree
536Construct Binary Tree from StringPremiumMediumStack, Tree, Depth-First Search +2
545Boundary of Binary TreePremiumMediumTree, Depth-First Search, Binary Tree
549Binary Tree Longest Consecutive Sequence IIPremiumMediumTree, Depth-First Search, Binary Tree
582Kill ProcessPremiumMediumTree, Depth-First Search, Breadth-First Search +2
663Equal Tree PartitionPremiumMediumTree, Depth-First Search, Binary Tree
666Path Sum IVPremiumMediumTree, Depth-First Search, Array +2
742Closest Leaf in a Binary TreePremiumMediumTree, Depth-First Search, Breadth-First Search +1
776Split BSTPremiumMediumTree, Binary Search Tree, Recursion +1
814Binary Tree PruningMediumTree, Depth-First Search, Binary Tree
863All Nodes Distance K in Binary TreeMediumTree, Depth-First Search, Breadth-First Search +2
865Smallest Subtree with all the Deepest NodesMediumTree, Depth-First Search, Breadth-First Search +2
889Construct Binary Tree from Preorder and Postorder TraversalMediumTree, Array, Hash Table +2
894All Possible Full Binary TreesMediumTree, Recursion, Memoization +2
919Complete Binary Tree InserterMediumTree, Breadth-First Search, Design +1
951Flip Equivalent Binary TreesMediumTree, Depth-First Search, Binary Tree
958Check Completeness of a Binary TreeMediumTree, Breadth-First Search, Binary Tree
971Flip Binary Tree To Match Preorder TraversalMediumTree, Depth-First Search, Binary Tree
979Distribute Coins in Binary TreeMediumTree, Depth-First Search, Binary Tree
988Smallest String Starting From LeafMediumTree, Depth-First Search, String +2
998Maximum Binary Tree IIMediumTree, Binary Tree
1008Construct Binary Search Tree from Preorder TraversalMediumStack, Tree, Binary Search Tree +3
1026Maximum Difference Between Node and AncestorMediumTree, Depth-First Search, Binary Tree
1038Binary Search Tree to Greater Sum TreeMediumTree, Depth-First Search, Binary Search Tree +1
1080Insufficient Nodes in Root to Leaf PathsMediumTree, Depth-First Search, Binary Tree
1104Path In Zigzag Labelled Binary TreeMediumTree, Math, Binary Tree
1110Delete Nodes And Return ForestMediumTree, Depth-First Search, Array +2
1120Maximum Average SubtreePremiumMediumTree, Depth-First Search, Binary Tree
1123Lowest Common Ancestor of Deepest LeavesMediumTree, Depth-First Search, Breadth-First Search +2
1145Binary Tree Coloring GameMediumTree, Depth-First Search, Binary Tree
1214Two Sum BSTsPremiumMediumStack, Tree, Depth-First Search +4
1245Tree DiameterPremiumMediumTree, Depth-First Search, Breadth-First Search +2
1257Smallest Common RegionPremiumMediumTree, Depth-First Search, Breadth-First Search +3
1261Find Elements in a Contaminated Binary TreeMediumTree, Depth-First Search, Breadth-First Search +3
1273Delete Tree NodesPremiumMediumTree, Depth-First Search, Breadth-First Search +1
1302Deepest Leaves SumMediumTree, Depth-First Search, Breadth-First Search +1
1305All Elements in Two Binary Search TreesMediumTree, Depth-First Search, Binary Search Tree +2
1315Sum of Nodes with Even-Valued GrandparentMediumTree, Depth-First Search, Breadth-First Search +1
1325Delete Leaves With a Given ValueMediumTree, Depth-First Search, Binary Tree
1339Maximum Product of Splitted Binary TreeMediumTree, Depth-First Search, Binary Tree
1361Validate Binary Tree NodesMediumTree, Depth-First Search, Breadth-First Search +3
1367Linked List in Binary TreeMediumTree, Depth-First Search, Linked List +1
1376Time Needed to Inform All EmployeesMediumTree, Depth-First Search, Breadth-First Search
1382Balance a Binary Search TreeMediumGreedy, Tree, Depth-First Search +3
1430Check If a String Is a Valid Sequence from Root to Leaves Path in a Binary TreePremiumMediumTree, Depth-First Search, Breadth-First Search +1
1443Minimum Time to Collect All Apples in a TreeMediumTree, Depth-First Search, Breadth-First Search +1
1457Pseudo-Palindromic Paths in a Binary TreeMediumBit Manipulation, Tree, Depth-First Search +2
1485Clone Binary Tree With Random PointerPremiumMediumTree, Depth-First Search, Breadth-First Search +2
1490Clone N-ary TreePremiumMediumTree, Depth-First Search, Breadth-First Search +1
1506Find Root of N-Ary TreePremiumMediumBit Manipulation, Tree, Depth-First Search +1
1519Number of Nodes in the Sub-Tree With the Same LabelMediumTree, Depth-First Search, Breadth-First Search +2
1522Diameter of N-Ary TreePremiumMediumTree, Depth-First Search
1530Number of Good Leaf Nodes PairsMediumTree, Depth-First Search, Binary Tree
1586Binary Search Tree Iterator IIPremiumMediumStack, Tree, Design +3
1600Throne InheritanceMediumTree, Depth-First Search, Design +1
1602Find Nearest Right Node in Binary TreePremiumMediumTree, Breadth-First Search, Binary Tree
1609Even Odd TreeMediumTree, Breadth-First Search, Binary Tree
1612Check If Two Expression Trees are EquivalentPremiumMediumTree, Depth-First Search, Hash Table +2
1628Design an Expression Tree With Evaluate FunctionPremiumMediumStack, Tree, Design +3
1644Lowest Common Ancestor of a Binary Tree IIPremiumMediumTree, Depth-First Search, Binary Tree
1650Lowest Common Ancestor of a Binary Tree IIIPremiumMediumTree, Hash Table, Two Pointers +1
1660Correct a Binary TreePremiumMediumTree, Depth-First Search, Breadth-First Search +2
1666Change the Root of a Binary TreePremiumMediumTree, Depth-First Search, Binary Tree
1676Lowest Common Ancestor of a Binary Tree IVPremiumMediumTree, Depth-First Search, Hash Table +1
1740Find Distance in a Binary TreePremiumMediumTree, Depth-First Search, Breadth-First Search +2
1902Depth of BST Given Insertion OrderPremiumMediumTree, Binary Search Tree, Array +2
1973Count Nodes Equal to Sum of DescendantsPremiumMediumTree, Depth-First Search, Binary Tree
1993Operations on TreeMediumTree, Depth-First Search, Breadth-First Search +3
2049Count Nodes With the Highest ScoreMediumTree, Depth-First Search, Array +1
2096Step-By-Step Directions From a Binary Tree Node to AnotherMediumTree, Depth-First Search, String +1
2196Create Binary Tree From DescriptionsMediumTree, Array, Hash Table +1
2265Count Nodes Equal to Average of SubtreeMediumTree, Depth-First Search, Binary Tree
2368Reachable Nodes With RestrictionsMediumTree, Depth-First Search, Breadth-First Search +4
2378Choose Edges to Maximize Score in a TreePremiumMediumTree, Depth-First Search, Dynamic Programming
2385Amount of Time for Binary Tree to Be InfectedMediumTree, Depth-First Search, Breadth-First Search +2
2415Reverse Odd Levels of Binary TreeMediumTree, Depth-First Search, Breadth-First Search +1
2445Number of Nodes With Value OnePremiumMediumTree, Depth-First Search, Breadth-First Search +2
2467Most Profitable Path in a TreeMediumTree, Depth-First Search, Breadth-First Search +2
2471Minimum Number of Operations to Sort a Binary Tree by LevelMediumTree, Breadth-First Search, Binary Tree
2476Closest Nodes Queries in a Binary Search TreeMediumTree, Depth-First Search, Binary Search Tree +3
2477Minimum Fuel Cost to Report to the CapitalMediumTree, Depth-First Search, Breadth-First Search +1
2583Kth Largest Sum in a Binary TreeMediumTree, Breadth-First Search, Binary Tree +1
2641Cousins in Binary Tree IIMediumTree, Depth-First Search, Breadth-First Search +2
2673Make Costs of Paths Equal in a Binary TreeMediumGreedy, Tree, Array +2
2764Is Array a Preorder of Some ‌Binary TreePremiumMediumStack, Tree, Depth-First Search +1
2773Height of Special Binary TreePremiumMediumTree, Depth-First Search, Breadth-First Search +1
2925Maximum Score After Applying Operations on a TreeMediumTree, Depth-First Search, Dynamic Programming

Hard (42)

#ProblemDifficultyTopics
124Binary Tree Maximum Path SumHardTree, Depth-First Search, Dynamic Programming +1
297Serialize and Deserialize Binary TreeHardTree, Depth-First Search, Breadth-First Search +3
272Closest Binary Search Tree Value IIPremiumHardStack, Tree, Depth-First Search +4
428Serialize and Deserialize N-ary TreePremiumHardTree, Depth-First Search, Breadth-First Search +1
431Encode N-ary Tree to Binary TreePremiumHardTree, Depth-First Search, Breadth-First Search +2
834Sum of Distances in TreeHardTree, Depth-First Search, Graph +1
968Binary Tree CamerasHardTree, Depth-First Search, Dynamic Programming +1
987Vertical Order Traversal of a Binary TreeHardTree, Depth-First Search, Breadth-First Search +3
1028Recover a Tree From Preorder TraversalHardTree, Depth-First Search, String +1
1373Maximum Sum BST in Binary TreeHardTree, Depth-First Search, Binary Search Tree +2
1377Frog Position After T SecondsHardTree, Depth-First Search, Breadth-First Search +1
1483Kth Ancestor of a Tree NodeHardBit Manipulation, Tree, Depth-First Search +4
1516Move Sub-Tree of N-Ary TreePremiumHardTree, Depth-First Search
1569Number of Ways to Reorder Array to Get Same BSTHardTree, Union Find, Binary Search Tree +7
1597Build Binary Expression Tree From Infix ExpressionPremiumHardStack, Tree, String +1
1617Count Subtrees With Max Distance Between CitiesHardBit Manipulation, Tree, Dynamic Programming +2
1719Number Of Ways To Reconstruct A TreeHardTree, Graph
1766Tree of CoprimesHardTree, Depth-First Search, Array +2
1916Count Ways to Build Rooms in an Ant ColonyHardTree, Graph, Topological Sort +3
1932Merge BSTs to Create Single BSTHardTree, Depth-First Search, Hash Table +2
2003Smallest Missing Genetic Value in Each SubtreeHardTree, Depth-First Search, Union Find +1
2005Subtree Removal Game with Fibonacci TreePremiumHardTree, Math, Dynamic Programming +2
2246Longest Path With Different Adjacent CharactersHardTree, Depth-First Search, Graph +3
2277Closest Node to Path in TreePremiumHardTree, Depth-First Search, Breadth-First Search +1
2313Minimum Flips in Binary Tree to Get ResultPremiumHardTree, Depth-First Search, Dynamic Programming +1
2322Minimum Score After Removals on a TreeHardBit Manipulation, Tree, Depth-First Search +1
2421Number of Good PathsHardTree, Union Find, Graph +3
2440Create Components With Same ValueHardTree, Depth-First Search, Array +2
2458Height of Binary Tree After Subtree Removal QueriesHardTree, Depth-First Search, Breadth-First Search +2
2479Maximum XOR of Two Non-Overlapping SubtreesPremiumHardTree, Depth-First Search, Graph +1
2509Cycle Length Queries in a TreeHardTree, Array, Binary Tree
2538Difference Between Maximum and Minimum Price SumHardTree, Depth-First Search, Array +1
2581Count Number of Possible Root NodesHardTree, Depth-First Search, Array +2
2603Collect Coins in a TreeHardTree, Graph, Topological Sort +1
2646Minimize the Total Price of the TripsHardTree, Depth-First Search, Graph +2
2791Count Paths That Can Form a Palindrome in a TreeHardBit Manipulation, Tree, Depth-First Search +2
2792Count Nodes That Are Great EnoughPremiumHardTree, Depth-First Search, Divide and Conquer +1
2846Minimum Edge Weight Equilibrium Queries in a TreeHardTree, Graph, Array +1
2867Count Valid Paths in a TreeHardTree, Depth-First Search, Math +2
2872Maximum Number of K-Divisible ComponentsHardTree, Depth-First Search
2920Maximum Points After Collecting Coins From All NodesHardBit Manipulation, Tree, Depth-First Search +3
2973Find Number of Coins to Place in Tree NodesHardTree, Depth-First Search, Dynamic Programming +2

Related patterns

Problems sit in more than one pattern more often than not, and the overlap is where the interesting follow-up questions live.

Tree Traversal pattern FAQ

What is the tree traversal pattern?

Almost every binary tree problem is a traversal with a small amount of work attached, so the real decision is when the node gets processed relative to its children.

How many LeetCode problems use the tree traversal pattern?

This page lists 225 LeetCode problems that the tree traversal pattern applies to: 41 Easy, 142 Medium and 42 Hard. 167 of them carry a complete Python solution with complexity analysis.

What is the time complexity of the tree traversal pattern?

O(n) time and O(h), where h is the height of the tree space. Every node is visited exactly once whatever the order, so the time is linear in the node count. The space is the recursion stack or the explicit stack, which is the height of the tree: O(log n) on a balanced tree and O(n) on a degenerate one, and the degenerate one is what a test harness will hand you. Level-order traversal swaps the stack for a queue holding the widest level, which is up to n/2 nodes on a full tree.

When should I use the tree traversal pattern in an interview?

A value at each node depends on its subtrees — that is postorder. The tree is a BST and the question is about sorted order, a kth element, or a range.

Which tree traversal problem should I start with?

LeetCode 94. Binary Tree Inorder Traversal is the lowest-numbered Easy problem on this page, which makes it the usual starting point: the technique is visible without the problem's own complications getting in the way.

What patterns are related to tree traversal?

Depth-First Search, Breadth-First Search, Backtracking, Trie. Problems frequently sit in more than one of these, and the overlap is where the interesting follow-up questions come from.

More ways in: all 22 patterns, the curated study lists, or the full problem list.

Meet the tree traversal problem you did not practise

Stealth Interview is a desktop app for macOS and Windows. It reads the coding problem off your screen, returns a working solution with a step-by-step explanation and its time and space complexity, and transcribes what the interviewer is saying — while staying invisible to screen sharing.