Skip to main content

206. Reverse Linked List

easyAsked at Broadcom

Reverse a singly-linked list in place. Broadcom uses this to assess whether candidates can manipulate pointer arithmetic cleanly — a skill that maps directly to working with descriptor rings and buffer chains in network interface card drivers.

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

Source citations

Public interview reports confirming this problem appears in Broadcom loops.

  • Glassdoor (2026-Q1)Cited in Broadcom firmware and driver team interview feedback as a pointer-manipulation screen.
  • Blind (2025-11)Broadcom SWE candidates report linked-list reversal appearing in both phone and 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: The list is reversed in-place by rewiring each node's next pointer.

Example 2

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

Explanation: Two-node case — the tail becomes head.

Example 3

Input
head = []
Output
[]

Explanation: Empty list returns null.

Approaches

1. Iterative (three-pointer)

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

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, O(n) time. Preferred in embedded/driver contexts where stack space is limited — Broadcom interviewers will ask for this version specifically.

2. Recursive

Recurse to the tail, then wire each node's next.next = node and node.next = null on the way back.

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

Tradeoff: Elegant but O(n) stack depth — problematic for large lists or constrained stack environments like kernel drivers. Mention this tradeoff explicitly at Broadcom.

Broadcom-specific tips

Broadcom interviewers — especially on firmware and NIC driver teams — appreciate you drawing the pointer diagram before coding. Say: 'I'll use the iterative approach because it's O(1) space and safe in stack-constrained kernel contexts.' If asked for the recursive version, deliver it but proactively flag the stack-depth risk. The C analogue (raw pointer manipulation) may come up as a follow-up.

Common mistakes

  • Losing the reference to curr.next before overwriting curr.next — always save next = curr.next first.
  • Returning curr instead of prev — curr is null at loop end; prev holds the new head.
  • Not handling the null or single-node edge cases before coding.
  • Forgetting to set head.next = null in the recursive version — creates a cycle at the original head.

Follow-up questions

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

  • Reverse a linked list in groups of k (LC 25).
  • How would you reverse only a subrange [left, right] of the list (LC 92)?
  • How does this change in a doubly-linked list?

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 do Broadcom interviewers prefer the iterative version?

Firmware and driver engineers work in stack-constrained environments. O(1) space iterative code is safer and more production-realistic than recursion.

Why does the iterative loop return prev instead of curr?

At loop termination, curr === null and prev points to the former tail — the new head of the reversed list.

What if the list has a cycle?

The while loop would run forever. In a real system you'd detect cycles first (Floyd's algorithm) before attempting reversal.

Practice these live with InterviewChamp.AI

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

Practice these live with InterviewChamp.AI →