206. Reverse Linked List
easyReverse a singly linked list. The simplest pointer-rewiring drill — every interviewer expects an iterative O(1)-space solve and a clean recursive variant.
By Sam K., Founder, InterviewChamp.AI · Last verified
Problem
Given the head of a singly linked list, reverse the list, and return the reversed list.
Constraints
The number of nodes in the list is in the range [0, 5000].-5000 <= Node.val <= 5000
Examples
Example 1
head = [1,2,3,4,5][5,4,3,2,1]Example 2
head = [1,2][2,1]Example 3
head = [][]Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
Hints
Progressive — try the first before opening the next.
Hint 1
Three pointers: previous, current, next.
Hint 2
On each step: stash next = current.next; rewire current.next = previous; advance previous = current and current = next.
Hint 3
When current is null, previous is the new head — return it.
Solution approach
Reveal approach
Iterative three-pointer rewiring. previous starts as null, current starts as head. Loop while current is not null: stash next = current.next, rewire current.next to point at previous, then advance previous = current and current = next. When the loop ends, previous is the head of the reversed list. O(n) time, O(1) extra space. Recursive variant: recurse on head.next to get newHead, set head.next.next = head, set head.next = null, return newHead — O(n) time and O(n) recursion stack space.
Complexity
- Time
- O(n)
- Space
- O(1)
Related patterns
- linked-list
- pointer-rewiring
Related problems
Asked at
Companies reported asking this problem (sourced from public Glassdoor, Blind, and Levels.fyi interview posts).
- Amazon
- Meta
- Microsoft
- Apple
- Bloomberg
More Linked Lists practice problems
- 2. Add Two Numbers
- 19. Remove Nth Node From End of List
- 21. Merge Two Sorted Lists
- 24. Swap Nodes in Pairs
- 25. Reverse Nodes in k-Group
- 61. Rotate List
- 82. Remove Duplicates from Sorted List II
- 83. Remove Duplicates from Sorted List