Optimize traversal for without recursion
Last updated: April 25, 2026
Quick Overview
Given a binary tree, implement a function to traverse the tree in-order without using recursion. The function should take the root node of the tree as input and return a list of values representing the in-order traversal of the tree nodes.
DoorDash
April 25, 2026241
0
4,357 solved
Given a binary tree, implement a function to traverse the tree in-order without using recursion. The function should take the root node of the tree as input and return a list of values representing the in-order traversal of the tree nodes.
DoorDash uses this problem in the Onsite to evaluate your algorithmic thinking. They expect you to discuss multiple approaches, analyze trade-offs between them, and implement the optimal solution with clean, readable code.
What the Interviewer Expects
- Identify the correct data structure and algorithm for the problem
- Write clean, bug-free code with proper variable naming
- Analyze time and space complexity correctly
- Handle basic edge cases (empty input, single element)
- Communicate your thought process while coding
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What is the worst-case input for your solution?
- How would your solution change if the input was sorted?
- How would you parallelize this solution?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Problem Analysis
In this problem, we need to perform an in-order traversal of a binary tree without using recursion. The in-order traversal visits nodes in the following order: left subtree, current node, right subtre...
Approach
- Initialize an empty stack to keep track of nodes and an empty result list to store the traversal order.
- Start from the root node and push all the left nodes onto the stack until you reach a null...