← Two Pointers

Pattern Recognition Drill

#11 — Reverse a linked list

Easy Linked Lists

The Problem

Reverse a singly linked list in-place.

What approach would you use?

Think about it before scrolling down.

Key Signals

Two Pointers

prev/cur/next pattern: save next, point cur back to prev, advance both. O(n) time, O(1) space.

Alt: DFS / Recursion

Recursive reversal: reverse the rest, then make cur.next.next = cur. Elegant but O(n) stack space.

Common Trap

Don't lose the reference to next_node before rewiring — save it first, then modify cur.next.

← #10 #12 →