Skip to main content

30. Reverse Linked List

easyAsked at Workday

Reverse a singly linked list. Workday uses this for pointer hygiene — the same prev/curr/next dance needed when reversing an audit-log timeline.

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

Source citations

Public interview reports confirming this problem appears in Workday loops.

  • Glassdoor (2025)Workday SDE1 phone screen — list-manipulation warmup.

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

Approaches

1. Recursive reverse

Reverse the tail, then point the second node back to head.

Time
O(n)
Space
O(n) 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 O(n) stack. Risky for 5000-node inputs.

2. Iterative three-pointer

prev = null, curr = head. Save next, rewire curr.next to prev, advance.

Time
O(n)
Space
O(1)
function reverseList(head) {
  let prev = null;
  let curr = head;
  while (curr) {
    const next = curr.next;
    curr.next = prev;
    prev = curr;
    curr = next;
  }
  return prev;
}

Tradeoff: O(1) space. The save-next-before-overwrite is the canonical pattern.

Workday-specific tips

Workday grades whether you save curr.next BEFORE overwriting it. Without that save, you lose the rest of the list. Walk through the four-step iteration order (save, rewire, advance-prev, advance-curr) before coding.

Common mistakes

  • Forgetting to save next before overwriting curr.next.
  • Returning curr instead of prev — curr is null at the end.
  • Starting prev at head instead of null — the head's next ends up pointing to itself.

Follow-up questions

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

  • Reverse Linked List II (LC 92) — reverse only a range.
  • Palindrome Linked List (LC 234) — reverse the second half.
  • Reverse Nodes in k-Group (LC 25).

Solve it now

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

Output

Press Run or Cmd+Enter to execute

FAQ

Iterative or recursive?

Iterative is O(1) space and what Workday wants. Recursive is elegant but the stack frames are an interview tax.

Why prev = null to start?

The original head becomes the new tail. Its next must be null after reversal — starting prev at null bakes that in.

Practice these live with InterviewChamp.AI

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

Practice these live with InterviewChamp.AI →