Inorder Traversal Without Recursion
Updated
Problem statement
Given the root of a binary tree, return its node values in in-order: first the left subtree in in-order, then the node itself, then the right subtree in in-order.
Follow-up: solve it without recursion. The judge checks only the returned list, not how it was built; note that a tree here can be up to 2000 levels deep.
Function
inorderValues(root: TreeNode) → List<Integer>Examples
Example 1
root = [5,8,1,null,3,6]return = [8,3,5,6,1]The left subtree of 5 is 8 with a right child 3, which gives 8, 3. Then comes 5 itself. The right subtree is 1 with a left child 6, which gives 6, 1. In-order: [8, 3, 5, 6, 1].
Example 2
root = [-2,7,null,4,null,0]return = [0,4,7,-2]Every node has only a left child, so the walk goes all the way down first: 0, then 4, 7 and finally the root -2.
Example 3
root = [11]return = [11]A single node: [11].
Constraints
- The tree has
1to2000nodes. -10^4 <= Node.val <= 10^4
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Binary Tree Preorder TraversalMorgan Stanley · PHONE SCREENMorgan Stanley interview questions
- Binary Tree Inorder TraversalBloomberg LP · PHONE SCREENBloomberg LP interview questions
- Validate a BST with a Custom ComparisonApple · PHONE SCREENApple interview questions
- Find File Paths in a Directory TreeUber · PHONE SCREENUber interview questions
- Delete a Filesystem TreeDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Serialize and Deserialize a Binary TreeNVIDIA · PHONE SCREENNVIDIA interview questions
- Kth Smallest Value in a BSTExpedia · PHONE SCREEN · ONSITE INTERVIEWExpedia interview questions
- Kth Smallest Element in a BSTNutanix · PHONE SCREENNutanix interview questions
- Recover a Tree from Preorder Depth EncodingSuperhuman · PHONE SCREENSuperhuman interview questions
- Binary Tree Preorder TraversalAnduril · ONSITE INTERVIEWAnduril interview questions