Skip to main content

206. Reverse Linked List

easy

Reverse a singly linked list. The simplest pointer-rewiring drill — every interviewer expects an iterative O(1)-space solve and a clean recursive variant.

By Alex Chen, 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

Input
head = [1,2,3,4,5]
Output
[5,4,3,2,1]

Example 2

Input
head = [1,2]
Output
[2,1]

Example 3

Input
head = []
Output
[]

Solve it now

Free. No sign-up. Python and JavaScript run instantly in your browser.

Output

Press Run or Cmd+Enter to execute

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

Practice these live with InterviewChamp.AI

Drill Reverse Linked List and Linked Lists problems under real interview conditions with instant feedback on your reasoning, complexity claims, and code.

Practice these live with InterviewChamp.AI →