Skip to main content

206. Reverse Linked List

easyAsked at Intel

Reverse a singly linked list. Intel uses this in SWE phone screens to confirm pointer-mechanics fluency before moving on. The iterative three-pointer dance and the tail-recursive variant both come up; senior candidates write both without prompting.

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

Source citations

Public interview reports confirming this problem appears in Intel loops.

  • Glassdoor (2026-Q1)Intel SWE phone-screen reports list reverse-linked-list as a foundational warm-up.
  • GeeksforGeeks (2025-08)Intel Interview Experience archives reference both iterative and recursive answers.
  • LeetCode discuss (2025-12)Intel-tagged in the LC company-frequency listing.

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. Stack-based (brute)

Walk forward, push each node onto a stack. Pop and rewire next pointers.

Time
O(n)
Space
O(n)
function reverseListStack(head) {
  const stack = [];
  let curr = head;
  while (curr) { stack.push(curr); curr = curr.next; }
  if (stack.length === 0) return null;
  const newHead = stack[stack.length - 1];
  let node = stack.pop();
  while (stack.length > 0) {
    const prev = stack.pop();
    node.next = prev;
    node = prev;
  }
  node.next = null;
  return newHead;
}

Tradeoff: Works but uses O(n) extra space. Mention it once to show you can think with auxiliary structures, then immediately move to the in-place version.

2. Iterative three-pointer (optimal)

Walk forward, flipping each next pointer to point backward. Maintain prev, curr, and a saved next.

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

Tradeoff: Linear time, constant space, in-place. The canonical answer. Drawing the four-step swap on the whiteboard (save next → flip → advance prev → advance curr) is the senior signal.

3. Recursive (elegant alternative)

Reverse the tail first, then make the original next-node point back to the current node.

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

Tradeoff: Beautiful but uses O(n) stack space and risks stack overflow for very long lists. Mention it as the 'elegant' option; ship the iterative version in production code.

Intel-specific tips

Intel interviewers want both versions if there's time. The 'why iterative ships' explanation matters: 'In firmware or driver code, the call stack is shallow and bounded; an O(n) stack-depth recursion on a long list could overflow. The iterative version has the same correctness with bounded stack.' That observation is the Intel-flavored systems signal.

Common mistakes

  • Forgetting to save curr.next BEFORE flipping curr.next = prev — once you flip, you've lost the way to the rest of the list.
  • In the recursive version, forgetting head.next = null on the base case — leaves a cycle.
  • Returning the wrong end of the list. The new head is the old tail (which is `prev` at the end of the iterative loop).

Follow-up questions

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

  • Reverse Linked List II (LC 92) — reverse only between positions left and right.
  • Reverse Nodes in k-Group (LC 25) — reverse in chunks of k.
  • Palindrome Linked List (LC 234) — half-reverse + compare.
  • What if the list is doubly-linked? (Swap each node's prev and next; one pass.)

Solve it now

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

Output

Press Run or Cmd+Enter to execute

FAQ

Why is the new head equal to `prev` at the end of the loop?

The loop terminates when curr is null. The last node we processed has its next set to the previous-prev, and we've advanced prev to that last node. So prev IS the old tail, which is the new head.

Could I do this without saving next?

Not in a singly-linked list. Once you overwrite curr.next, the link to the rest of the list is gone. You MUST save it before the flip — that's the entire point of the three-pointer pattern.

Free learning resources

Curated free links for this problem.

Practice these live with InterviewChamp.AI

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

Practice these live with InterviewChamp.AI →