← Two Pointers

Pattern Recognition Drill

#1 — Reverse array in-place

Easy Arrays & Strings

The Problem

Given an array a, reverse it in-place.

What approach would you use?

Think about it before scrolling down.

Key Signals

Two Pointers

Swap elements at left and right pointers, converge toward center. O(n) time, O(1) space.

Alt: Stack

Push all → pop all gives reversed order, but uses O(n) space — violates in-place requirement.

Common Trap

Don't reach for slicing (a[::-1]) in an interview — it creates a new array, not in-place.

#2 →