Skip to main content

206. Reverse Linked List

easyAsked at Akamai

Reverse a singly linked list in place. Akamai uses this to verify that candidates can reason about pointer manipulation without extra memory — a discipline that matters in high-throughput packet-processing code where heap allocations are expensive.

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

Source citations

Public interview reports confirming this problem appears in Akamai loops.

  • Glassdoor (2026-Q1)Akamai SWE interview reports list Reverse Linked List as a standard early-round data structures question.
  • Blind (2025-11)Candidates note Akamai phone screens frequently include linked list manipulation problems.

Problem

Given the head of a singly linked list, reverse the list and return the reversed list's head.

Constraints

  • The number of nodes 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]

Explanation: All pointers reversed; former tail becomes new head.

Example 2

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

Explanation: Two-node list reversed.

Example 3

Input
head = []
Output
[]

Explanation: Empty list remains empty.

Approaches

1. Iterative (three-pointer)

Walk the list with three pointers: prev, curr, next. At each step, reverse the curr.next pointer, advance all three pointers forward, and continue.

Time
O(n)
Space
O(1)
function reverseList(head) {
  let prev = null;
  let curr = head;
  while (curr !== null) {
    const next = curr.next; // save forward reference
    curr.next = prev;       // reverse the pointer
    prev = curr;            // advance prev
    curr = next;            // advance curr
  }
  return prev; // prev is the new head
}

Tradeoff: O(n) time, O(1) space. Preferred by Akamai because it demonstrates in-place pointer manipulation without relying on the call stack or extra memory.

2. Recursive

Recurse to the tail, then fix pointers on the way back up. The tail becomes the new head.

Time
O(n)
Space
O(n) stack
function reverseList(head) {
  if (head === null || head.next === null) return head;
  const newHead = reverseList(head.next);
  head.next.next = head; // make next node point back
  head.next = null;      // cut forward pointer
  return newHead;
}

Tradeoff: Elegant but uses O(n) stack space. For large lists (n = 5000) this is fine, but Akamai will ask about the space trade-off. Prefer the iterative solution when stack depth matters.

Akamai-specific tips

Draw the pointer diagram before coding. Akamai interviewers respond well to candidates who sketch three nodes and trace each pointer reassignment. Explicitly name the invariant: 'At the top of each loop iteration, prev is the already-reversed portion and curr is the start of the unreversed portion.' This shows the systematic thinking that Akamai prizes.

Common mistakes

  • Saving next after the reversal instead of before — curr.next is already null at that point, so you lose the rest of the list.
  • Returning curr instead of prev at the end — curr is null at loop exit; prev holds the new head.
  • Forgetting to set head.next = null in the recursive version — creates a cycle between the first two nodes.

Follow-up questions

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

  • Reverse Linked List II (LC 92) — reverse only a subrange [left, right].
  • How would you reverse a doubly-linked list?
  • Palindrome Linked List (LC 234) — reverse the second half in place to check symmetry.

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 does prev start as null?

The original head's next pointer must become null after reversal (it will be the new tail). Initializing prev = null handles this naturally without a special case.

Which approach does Akamai prefer?

The iterative version — Akamai's infrastructure background means interviewers notice and appreciate O(1) space solutions.

Practice these live with InterviewChamp.AI

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

Practice these live with InterviewChamp.AI →