Skip to main content

206. Reverse Linked List

easyAsked at IBM

Reverse Linked List is IBM's canonical pointer warm-up across SWE phone screens. The interviewer is grading whether you can walk a singly linked list with three pointers without losing the tail and whether you can articulate the recursive variant's stack cost.

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

Source citations

Public interview reports confirming this problem appears in IBM loops.

  • Glassdoor (2026-Q1)Appears in IBM SWE-1 / SWE-2 phone-screen reports as the first 10-minute warm-up.
  • LeetCode (2026-Q1)Tagged under IBM company-frequency list (top 50 IBM-asked problems).
  • GeeksforGeeks (2025-12)Listed in 'IBM most-asked interview questions' compilation.

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

Explanation: Empty list returns empty.

Approaches

1. Recursive (clean, stack-bound)

Recurse to the tail, then flip pointers on the way back up.

Time
O(n)
Space
O(n) call stack
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: Easiest to derive on a whiteboard but O(n) stack overflows on the 5000-node upper bound in JS engines with small stack limits. Mention this trap before you commit to it on a follow-up with larger inputs.

2. Iterative three-pointer (optimal)

Walk the list once with prev / curr / next. Reverse the curr->next pointer, then advance.

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: Constant extra space and the textbook answer. Saving `next` BEFORE the pointer flip is the line candidates most often forget — losing it strands the rest of the list.

IBM-specific tips

IBM interviewers want to see you draw the three pointers (prev, curr, next) on the whiteboard before you write code. Many candidates jump straight to the loop and overwrite `curr.next` before saving `next` — narrating the order of operations earns rubric points. If you reach for recursion, name the O(n) stack cost so the interviewer doesn't think you missed it.

Common mistakes

  • Overwriting curr.next before saving the next pointer — strands the rest of the list.
  • Returning head instead of prev at the end — head is now the tail.
  • Forgetting to set head.next = null in the recursive base case, creating a cycle.
  • Off-by-one on the loop condition (using curr.next !== null instead of curr !== null) — misses the last flip.

Follow-up questions

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

  • Reverse a linked list between positions m and n (LeetCode 92).
  • Reverse nodes in k-group (LeetCode 25).
  • Detect whether the list has a cycle (Floyd's tortoise and hare).
  • Reverse a doubly linked list — does your code still work with prev pointers?

Solve it now

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

Output

Press Run or Cmd+Enter to execute

FAQ

Does IBM still ask Reverse Linked List in 2026?

Yes — it remains a foundational warm-up across IBM SWE phone screens, particularly for SWE-1 and SWE-2 (new-grad and 2-3 YOE). Expect a follow-up like reverse-in-k-group or reverse-between in the onsite if you breeze through it.

Should I write the recursive or iterative solution first?

Iterative. The three-pointer version is O(1) space and considered the canonical answer; the recursive version is fine to mention as a 'one-liner if recursion is allowed' but explicitly call out the O(n) stack cost or the interviewer will assume you missed it.

Free learning resources

Curated free links for this problem.

Practice these live with InterviewChamp.AI

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

Practice these live with InterviewChamp.AI →