Medium · Trees

Binary tree traversal iteratively

Given the root of a binary tree, return its in-order traversal (left subtree, node, right subtree) as a list of values, computed without recursion; an empty tree returns [].

Examples

Example 1

{
  "tree": [1, 2, 3, 4, 5]
}

Output: [4, 2, 5, 1, 3]

Example 2

{
  "tree": [2, 1, 3, null, null, null, 4]
}

Output: [1, 2, 3, 4]

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Trees problems