WorkspaceProblem lab
ALGORITHM VISUALIZER

Binary Tree Inorder Traversal

Opening the interactive workspace…

Understanding Inorder Traversal

Return binary tree values in left–root–right order. The input is a level-order array with null marking missing children; your function receives a TreeNode or null.

How it works

An explicit stack remembers ancestors whose left subtrees are still being processed.

Push the entire left spine. Pop and visit one node, then repeat from its right child.

Try an example

Input: values = [1, null, 2, 3]

Output: [1, 3, 2]

Visit node 1, then the left child of node 2, then node 2.

Constraints

  • At most 31 level-order entries.
  • Values may repeat; node identity is separate from value.
  • An empty tree returns an empty array.

Use the simulator

Change the input, then choose Visualize input. Use Next and Previous to inspect each decision, or Play to advance automatically. Compare approaches and their complexity. Choose Try yourself to write JavaScript, select My code and Visualize code to inspect its execution, or Run Tests to check results.

Execution happens in your browser. Drafts are saved locally; avoid entering secrets or sensitive information.

Related concepts and complexity