Skip to main content

9. Binary Tree Inorder Traversal

easyAsked at Figma

Return the inorder traversal of a binary tree's nodes' values. Figma uses this as a tree-traversal warm-up because their scene-graph walk-order (top-down, then siblings in z-order) follows the same recursive structure.

By Alex Chen, Founder, InterviewChamp.AI · Last verified

Source citations

Public interview reports confirming this problem appears in Figma loops.

  • Glassdoor (2026-Q1)Onsite tree-traversal warm-up.
  • LeetCode Discuss (2025)Frequently in Figma OAs as preparation for harder canvas problems.

Problem

Given the root of a binary tree, return the inorder traversal of its nodes' values.

Constraints

  • The number of nodes in the tree is in the range [0, 100].
  • -100 <= Node.val <= 100

Examples

Example 1

Input
root = [1,null,2,3]
Output
[1,3,2]

Example 2

Input
root = []
Output
[]

Approaches

1. Recursive

Left, root, right — straightforward DFS.

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 direct. Interviewers often follow up with 'now do it iteratively' — be ready.

2. Iterative with explicit stack

Push all lefts, pop and record, then move to right. Repeat.

Time
O(n)
Space
O(h)
function inorderTraversal(root) {
  const out = [], stack = [];
  let curr = root;
  while (curr || stack.length) {
    while (curr) {
      stack.push(curr);
      curr = curr.left;
    }
    curr = stack.pop();
    out.push(curr.val);
    curr = curr.right;
  }
  return out;
}

Tradeoff: Same complexity but exposes the stack explicitly — useful when the tree is taller than the call-stack budget.

Figma-specific tips

Figma's scene graph has hundreds of thousands of nodes in large files, so they want you ready for the iterative version when 'depth might exceed call-stack budget' is hinted at. Mention both versions and pick the iterative one if they ask about a million-node tree — that signals you've thought about Figma's scale, not just LeetCode's.

Common mistakes

  • Pushing the node BEFORE going all the way left — produces preorder by accident.
  • Forgetting to set curr = curr.right after popping — infinite loop.
  • Trying Morris traversal without practicing it first — easy to corrupt the tree.

Follow-up questions

An interviewer at Figma may pivot to one of these next:

  • Preorder, postorder, level-order variants.
  • Morris traversal (O(1) extra space using threading).
  • Validate BST (LC 98) — uses the inorder property that values must be increasing.

Solve it now

Free. No sign-up. Python and JavaScript run instantly in your browser.

Output

Press Run or Cmd+Enter to execute

FAQ

Why is inorder useful for BSTs?

Inorder traversal of a BST yields values in sorted order. That's why Validate BST and many BST problems lean on it.

What's Morris traversal?

An O(1) extra-space iterative traversal that temporarily threads predecessors back to successors. Powerful but easy to mess up; only do it if you've drilled it.

Practice these live with InterviewChamp.AI

Drill Binary Tree Inorder Traversal and other Figma interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.

Practice these live with InterviewChamp.AI →