Skip to main content

206. Reverse Linked List

easyAsked at AMD

Reverse a singly linked list in-place. AMD uses this to probe pointer manipulation — the same mental model you need when traversing hardware descriptor chains, DMA linked lists, or command ring buffers in GPU driver code.

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

Source citations

Public interview reports confirming this problem appears in AMD loops.

  • Glassdoor (2026-Q1)AMD driver/firmware role interviewers cite Reverse Linked List as a standard pointer-manipulation check.
  • Blind (2025-09)AMD interview prep posts highlight this as an expected easy in SWE onsite rounds.

Problem

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

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]

Explanation: All pointers reversed in place.

Example 2

Input
head = []
Output
[]

Explanation: Empty list returns null.

Approaches

1. Iterative (three-pointer)

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

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: O(1) space — no stack or recursion. This is the preferred answer at AMD where memory efficiency matters.

2. Recursive

Recurse to the end of the list, then on the way back reverse each pointer.

Time
O(n)
Space
O(n) call 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: Elegant but uses O(n) call stack. For hardware/driver contexts at AMD the iterative version is preferred to avoid stack overflow on long lists.

AMD-specific tips

In AMD driver and firmware roles, linked lists appear in command queues, descriptor rings, and DMA chains. Mention the hardware parallel when discussing the problem: reversing a descriptor chain in a GPU command buffer uses the same pointer-swap logic. AMD interviewers appreciate candidates who connect algorithm fundamentals to real hardware data structures. Always mention the null sentinel check for empty and single-node lists.

Common mistakes

  • Forgetting to save next before overwriting curr.next — this breaks the traversal.
  • Returning curr instead of prev at the end — curr is null when the loop exits, prev is the new head.
  • Not handling the empty list — head could be null.
  • Recursive solution stack-overflowing on very long lists — mention this limitation proactively.

Follow-up questions

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

  • Reverse Linked List II (LC 92) — reverse only a subrange [left, right].
  • Reverse Nodes in k-Group (LC 25) — reverse in groups of k.
  • How would you reverse a doubly-linked list? (Swap prev and next 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

Why does the iterative version need three pointers?

You need prev to set the new next pointer, curr to process the current node, and next to avoid losing the rest of the list when you overwrite curr.next.

What does the function return when the input is a single node?

The single node itself — prev starts at null, curr moves to the single node, the loop body sets curr.next = null (already null), prev = curr, curr = null. Returns prev which is the single node.

Practice these live with InterviewChamp.AI

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

Practice these live with InterviewChamp.AI →