Skip to main content

206. Reverse Linked List

easyAsked at Microsoft

Reverse Linked List is Microsoft's go-to pointer-manipulation warm-up. Interviewers want you to talk through the three-pointer dance (prev, curr, next) without losing the rest of the list and to mention the recursive variant before they ask.

By Alex Chen, Founder, InterviewChamp.AI · Last verified

Source citations

Public interview reports confirming this problem appears in Microsoft loops.

  • Glassdoor (2026-Q1)Microsoft SWE-new-grad onsite reports list this as a 15-minute warm-up before a harder linked-list follow-up.
  • Levels.fyi (2026-Q1)Microsoft L60 interview compilation flags Reverse Linked List as the most-repeated linked-list question.

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 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
[]

Approaches

1. Iterative three-pointer (optimal)

Walk the list with prev = null, curr = head. At each step save next, flip curr.next to prev, then advance prev and curr.

Time
O(n)
Space
O(1)
function reverseList(head) {
  let prev = null;
  let curr = head;
  while (curr) {
    const next = curr.next;
    curr.next = prev;
    prev = curr;
    curr = next;
  }
  return prev;
}

Tradeoff: Single linear scan with constant extra space. The 'save next first' line is the one most people forget; without it you lose the rest of the list the moment you reassign curr.next.

2. Recursive

Recurse to the tail, then on the way back flip each node so head.next.next = head and head.next = null.

Time
O(n)
Space
O(n) recursion stack
function reverseList(head) {
  if (!head || !head.next) return head;
  const newHead = reverseList(head.next);
  head.next.next = head;
  head.next = null;
  return newHead;
}

Tradeoff: Cleaner three lines of logic but pays O(n) stack space. Microsoft interviewers will sometimes ask you to write both — the recursive version is a checkpoint on whether you can reason about returns walking back up the stack.

Microsoft-specific tips

Microsoft cares about the pointer narration specifically. Draw three boxes on the whiteboard labeled prev, curr, next BEFORE writing any code, and walk through one iteration with arrows. Reviewers consistently flag candidates who skip straight to typing because the bug surface (lost next pointer, returning curr instead of prev) is identical across years.

Common mistakes

  • Returning curr (which is null when the loop exits) instead of prev.
  • Forgetting to save curr.next BEFORE reassigning curr.next = prev — destroys the rest of the list.
  • In the recursive version, forgetting to set head.next = null on the unwind — creates a cycle of length 2 at the original head.

Follow-up questions

An interviewer at Microsoft may pivot to one of these next:

  • Reverse Linked List II (LC 92) — reverse only between positions m and n.
  • Reverse Nodes in k-Group (LC 25) — same idea applied in chunks.
  • Palindrome Linked List (LC 234) — reverse second half in place to check.

Solve it now

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

Output

Press Run or Cmd+Enter to execute

FAQ

Should I write iterative or recursive first?

Iterative. It's O(1) space and that's what Microsoft wants to see as your first instinct. Mention the recursive variant exists; only write it if the interviewer asks.

What about reversing a doubly linked list?

Same three-pointer skeleton but you also swap prev and next on each node. Microsoft sometimes pivots to this as a follow-up if the singly-linked version goes fast.

Free learning resources

Curated free links for this problem.

Practice these live with InterviewChamp.AI

Drill Reverse Linked List and other Microsoft interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.

Practice these live with InterviewChamp.AI →