Skip to main content

206. Reverse Linked List

easyAsked at HubSpot

HubSpot includes Reverse Linked List to confirm you can manipulate pointer-based structures precisely — an essential skill for engineers working on their pipeline and activity-feed data models where ordered traversal matters.

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

Source citations

Public interview reports confirming this problem appears in HubSpot loops.

  • Glassdoor (2026-Q1)HubSpot SWE candidates report Reverse Linked List appearing in technical phone screens.
  • Levels.fyi (2025-12)Listed in HubSpot interview experience posts as a standard linked-list warm-up problem.

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: Each node's next pointer is reversed so 5 becomes the new head.

Example 2

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

Explanation: Two-node list: the pointer from 2 to 1 replaces the pointer from 1 to 2.

Approaches

1. Iterative (three-pointer)

Walk the list with three pointers: prev (starts null), curr (starts at head), and next. At each step, redirect curr.next to prev, then advance all three pointers forward.

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 link
    prev = curr;            // advance prev
    curr = next;            // advance curr
  }
  return prev; // prev is the new head
}

Tradeoff: O(1) extra space, O(n) time. The canonical answer. Saving curr.next before overwriting it is the critical step — missing it loses the rest of the list. HubSpot interviewers will ask you to trace through a 3-node example.

2. Recursive

Recurse to the tail, then on the way back out, redirect each node's next pointer to point backwards and null out the original forward link.

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; // redirect the next node back to us
  head.next = null;      // break the original forward link
  return newHead;
}

Tradeoff: Elegant but uses O(n) call-stack space — a risk for very long lists. Good to mention as an alternative after presenting the iterative solution. HubSpot may ask which you'd use in production (iterative — no stack overflow risk).

HubSpot-specific tips

State the approach before coding: 'I'll use three pointers — prev, curr, and next — to reverse links in one pass.' Draw a 3-node diagram on the whiteboard or in comments. HubSpot values clear communication over speed. They often follow up with 'reverse only a portion of the list' (LC 92), so be ready to adapt your iterative pointer logic.

Common mistakes

  • Forgetting to save curr.next before redirecting curr.next = prev — this makes the rest of the list unreachable.
  • Returning curr instead of prev at the end — curr is null after the loop; prev is the new head.
  • Not handling the empty list (head = null) or single-node list as base cases.
  • Confusing which pointer to advance first — always save next, redirect link, advance prev, advance curr, in that order.

Follow-up questions

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

  • Reverse Linked List II (LC 92) — reverse only the nodes between positions left and right.
  • Palindrome Linked List (LC 234) — reverse the second half and compare with the first.
  • How would you reverse a doubly-linked list? (Swap next and prev pointers for each node.)

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 becomes the new tail, and its next pointer must point to null. Starting prev at null ensures that automatically.

Which approach is better in production?

Iterative — it uses O(1) space and avoids call-stack overflow for long lists. Reserve recursion for situations where the cleaner code justifies the space cost.

Can you reverse in place without extra data structures?

Yes — the iterative three-pointer approach modifies next pointers in place and uses only three extra variables regardless of list length.

Practice these live with InterviewChamp.AI

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

Practice these live with InterviewChamp.AI →