← Adobe questions

Reverse a stack without using another stack

Filed under Adobe

Free read 3 of 3

The 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

  1. If stack is empty, return.

Solution

O(N^2) time, O(N) space (call stack)

Python
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.