9. Binary Tree Inorder Traversal
easyAsked at IntuitReturn the inorder traversal of a binary tree's nodes' values. Intuit asks this in form-rule contexts — TurboTax stores conditional rules as trees and often needs deterministic left-to-right visitation order.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Intuit loops.
- Glassdoor (2025-11)— TurboTax engine team screen mention.
- LeetCode Discuss (2026-Q1)— Intuit phone-screen problem.
Problem
Given the root of a binary tree, return the inorder traversal of its nodes' values. Inorder = left subtree, current, right subtree. The follow-up is to do it iteratively.
Constraints
The number of nodes in the tree is in the range [0, 100].-100 <= Node.val <= 100
Examples
Example 1
root = [1,null,2,3][1,3,2]Example 2
root = [][]Example 3
root = [1][1]Approaches
1. Recursive (warm-up)
Recurse left, push current, recurse right.
- Time
- O(n)
- Space
- O(h) recursion stack
function inorderTraversal(root) {
const out = [];
function dfs(node) {
if (!node) return;
dfs(node.left);
out.push(node.val);
dfs(node.right);
}
dfs(root);
return out;
}Tradeoff: Clean and obvious. The follow-up is to remove the implicit recursion stack.
2. Iterative with explicit stack (optimal)
Use a stack. Push all left children. Pop, emit, then move to the right subtree and repeat.
- Time
- O(n)
- Space
- O(h)
function inorderTraversal(root) {
const out = [];
const 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: Same time/space asymptotically but avoids stack-overflow on deep trees. Useful when h is large.
Intuit-specific tips
Intuit interviewers may ask you to do BOTH versions and articulate when each is appropriate. Recursive is more readable; iterative is safer for very deep trees (e.g., a degenerate left-skewed tree built from a long sorted insertion sequence). Bonus signal: mention Morris traversal (O(1) extra space) as a deeper-level optimization without coding it.
Common mistakes
- Confusing inorder with preorder (root, left, right) — produces wrong output.
- Forgetting the inner while loop in iterative — pushes the same node twice.
- Not handling null root — recursive base case must check.
Follow-up questions
An interviewer at Intuit may pivot to one of these next:
- Preorder + postorder iterative.
- Morris traversal (O(1) extra space).
- Inorder successor of a node — used in BST iterators.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why inorder for a BST?
Inorder traversal of a BST visits nodes in sorted order — a property TurboTax exploits when ordering form questions by their dependency tree.
Recursive vs iterative — which does Intuit prefer?
Iterative gets bonus points because it's safer at scale. But have both ready; some interviewers grade on recursive first then ask 'now without recursion'.
Practice these live with InterviewChamp.AI
Drill Binary Tree Inorder Traversal and other Intuit interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →