Reverse a stack without using another stack
Filed under Adobe
Free read 3 of 3The question
Reverse a stack using only recursion (no additional stack or data structures).
Constraints
- Must use recursion
- No auxiliary stack allowed
- In-place modification of the stack
Examples
- Input
- [1, 2, 3]
- Output
- [3, 2, 1]
- Why
- The stack is reversed such that 3 is at the bottom.
Approach
If stack is empty, return.
Pop the top element and store it in the call stack.
Call a helper function to insert the popped element at the bottom of the stack.
Solution
O(N^2) time, O(N) space (call stack)
def reverse(stack):
if not stack: return
temp = stack.pop()
reverse(stack)
insert_at_bottom(stack, temp)
def insert_at_bottom(stack, item):
if not stack: stack.append(item)
else:
temp = stack.pop()
insert_at_bottom(stack, item)
stack.append(temp)
Tips
- What they are testing: Tests understanding of the call stack as an implicit data structure.
- Common mistake: Trying to solve it iteratively, which requires an extra data structure.
Related Adobe questions
Collected from public candidate posts and coding forums. Updated Nov 2026.