EasyVery High Frequency20 min
Reverse Linked List
Iterative and recursive reversal patterns — the most fundamental linked list operation.
Reverse a linked list in O(n) O(1) using three pointers. Reversing a sublist [m..n] requires finding and reconnecting boundary nodes.
Reverse a Linked List
Three-Pointer Reversal
Linked List1 / 13
Initial: prev=null, curr=head
The list is still 1 -> 2 -> 3 -> 4 -> null. curr starts at node 1 and prev is null.
Code
Iterative Reverse
O(n)O(1) space — preferred over recursive approachStep-by-step1 / 11
Initialize prev=null, curr=1
Original links: 1 -> 2 -> 3 -> 4 -> 5 -> null.
More in Linked Lists
Linked List Fundamentals
Singly, doubly, and circular linked lists — nodes, pointers, and traversal.
Fast & Slow Pointers (Floyd's)
Detect cycles, find midpoints, and solve linked list problems using two speed pointers.
Merge Lists & K-way Merge
Merge sorted lists using dummy node technique and a min-heap for K lists.