9. Binary Tree Inorder Traversal
easyAsked at ZoomReturn the inorder traversal of a binary tree's node values.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Problem
Given the root of a binary tree, return the inorder traversal of its nodes' values. Visit left subtree, then root, then right subtree.
Constraints
0 <= nodes <= 100-100 <= Node.val <= 100
Examples
Example 1
root=[1,null,2,3][1,3,2]Example 2
root=[][]Approaches
1. Recursive
Recurse left, push root, recurse right.
- Time
- O(n)
- Space
- O(h)
function inorder(r,out=[]){ if(!r) return out; inorder(r.left,out); out.push(r.val); inorder(r.right,out); return out;}Tradeoff:
2. Iterative with stack
Push left descendants on a stack; pop, record, then move right.
- Time
- O(n)
- Space
- O(h)
function inorderTraversal(root) {
const out = [], stack = [];
let cur = root;
while (cur || stack.length) {
while (cur) { stack.push(cur); cur = cur.left; }
cur = stack.pop();
out.push(cur.val);
cur = cur.right;
}
return out;
}Tradeoff:
Zoom-specific tips
Zoom's UI tree of meeting rooms / breakout subrooms is traversed inorder for the participant-roster panel — show the iterative version to prove stack-depth safety.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
Practice these live with InterviewChamp.AI
Drill Binary Tree Inorder Traversal and other Zoom interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →