AlgoViz
← All problems

Reverse Linked List

Easy+80 XPteaches: Linked List Traversal

Reverse a singly linked list. The animation shows the real prev/curr pointer reversal. For the editor we use an array as the list (head first) — return the reversed array, applying the same iterative idea.

Example: list = [1, 2, 3, 4] → [4, 3, 2, 1]

Iterative (prev / curr): Walk the list once, flipping each next pointer to point backward. (time O(n), space O(1))

No visualization loaded.

Watch

i

Press Run to begin.

0/0

Why the best approach wins

Reversal needs only three references — prev, curr, and the saved next — walking the list a single time and flipping each link. No extra data structure, O(1) memory.

Iterative (prev / curr): O(n) time / O(1) space

Your turn — implement reverseList

Loading editor…