← Stack

Pattern Recognition Drill

#22 — Reverse string with stack

Easy Stacks & Queues

The Problem

Reverse a string using a stack.

What approach would you use?

Think about it before scrolling down.

Key Signals

Stack

Push each character, pop all into result. LIFO reverses the order. O(n).

Alt: Two Pointers

In-place swap from both ends — more efficient (O(1) space) but the problem specifically asks for stack.

Common Trap

The problem constraints dictate the method here — 'using a stack' means use a stack.

← #21 #23 →