← Stack Discipline

Micro-Drill #40 — Stack to reverse

Stack Discipline Target: 10s

Using a stack to reverse order is the intuition behind reversing linked lists and strings.

stack = []
for x in a:
    stack.append(x)
reversed_a = []
while stack:
    reversed_a.append(stack.pop())

Type it from memory. Go.

Practice Problems

Related Coding Drills

← Micro #39 Micro #41 →