Binary Tree Inorder Traversal
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Strip away the tree vocabulary and Bloomberg's April 2020 Binary Tree Inorder Traversal is one rule: go left as far as you can, record the node, then go right. That's it. If you've got an OA invite and 24 to 72 hours, this is the kind of question you want to see. The catch is the 10^5 node cap, which quietly punishes sloppy recursion on a skewed tree. Know both the recursive and the iterative stack version cold. If your mind goes blank mid-assessment, StealthCoder sits invisibly on your screen and hands you the solution in real time, so one blank doesn't cost you the round.
The problem
Given the root of a binary tree, return its node values in inorder: left subtree, node, then right subtree. Function inorderTraversal(root: TreeNode) → int[] Examples Example 1 root = [1,null,2,3] return = [1,3,2] Visit 1, then the left child 3 of node 2, then node 2. Example 2 root = [] return = [] An empty tree has an empty traversal. Constraints The tree has at most 10^5 nodes. Node values are 32-bit signed integers.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The recursive version is three lines: recurse left, append the value, recurse right. It's correct, but with up to 10^5 nodes a fully skewed tree means 100,000 stack frames, which can overflow in some languages. The safer answer is iterative. Keep a stack and a current pointer. While current exists, push it and move left. When you can't go left, pop, append the value, then move to the popped node's right child. Loop until both the stack and current are empty. Time is O(n), space is O(h). The common pitfall is appending on push instead of on pop, which gives you preorder. Also handle the empty tree by returning an empty list. If you freeze on the pointer juggling during the live OA, StealthCoder is the hedge that gives you the working loop.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Binary Tree Inorder Traversal cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as binary tree inorder traversal. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Binary Tree Inorder Traversal FAQ
How hard is Bloomberg's Binary Tree Inorder Traversal really?+
It's easy. The recursive solution is a few lines. The only real risk is a skewed tree with 10^5 nodes, where deep recursion can overflow the stack. Write the iterative version once and you're covered either way.
What's the trick to inorder traversal?+
Process the left subtree fully, then the node, then the right subtree. Iteratively, push nodes while walking left, pop and record when you can't go further, then step into the right child. Record on pop, not on push.
Should I use recursion or an explicit stack?+
Recursion is fine for clarity, but the constraint allows 10^5 nodes, so a skewed tree can blow the call stack. An explicit stack is safer and shows you thought about limits. If you're unsure, go iterative.
What edge cases should I test?+
Test the empty tree, which must return an empty array. Test a single node, a tree with only left children, and a tree with only right children. The example [1,null,2,3] should return [1,3,2].
How do I prepare for this in 48 hours?+
Write inorder both ways from memory, then swap the order to get preorder and postorder so you don't mix them up. Trace Example 1 by hand. That covers this question and its close relatives.