Question Bank

Tree Traversal Challenge

Difficulty: Medium

Five mid-level prompts on in-order, pre-order, post-order, and level-order traversal. Code-anchored with one trace and one bug hunt.

Question Bank
/

Tree Traversal Challenge

Tree Traversal Challenge

Five mid-level prompts on in-order, pre-order, post-order, and level-order traversal. Code-anchored with one trace and one bug hunt.

Question Bank
Medium
JavaScript
5 questions
tree-traversal
trees
interview-prep
algorithms

940 views

22

Implement inorder(root) returning the in-order traversal of a binary tree as an array of values. Use either recursion or an explicit stack.

Examples

Example 1:

Input: BST 4 -> (2 -> (1, 3), 6 -> (5, 7))
Output: [1, 2, 3, 4, 5, 6, 7]
Explanation: In-order visits left subtree, node, right subtree. Iterative version pushes ancestors onto a stack while diving left, then pops, records the value, and dives into the right child. O(n) time, O(h) stack.