Stealth Interview
  • Features
  • Pricing
  • Blog
  • Login
  • Sign up

How to Solve Reverse Linked List on LeetCode

The Reverse Linked List problem is a classic data structures question that tests your mastery of pointer manipulation, iteration, and recursion.

Leetcode

Problem Statement

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

Example:

Input: head = [1,2,3,4,5] Output: [5,4,3,2,1]

Why This Problem Matters for Interviews

This problem:

  • Assesses pointer manipulation and understanding of linked list nodes
  • Distinguishes between iterative and recursive approaches
  • Forms a base for more complex linked list operations

Approaches to Reverse Linked List

1. Iterative Approach (Optimal)

Use three pointers: previous, current, next.

Time Complexity: O(n)
Space Complexity: O(1)

def reverseList(head): prev = None curr = head while curr: nxt = curr.next curr.next = prev prev = curr curr = nxt return prev

2. Recursive Approach

Reverse pointers as you return from recursion.

Time Complexity: O(n)
Space Complexity: O(n) for recursion stack

def reverseList(head): if not head or not head.next: return head p = reverseList(head.next) head.next.next = head head.next = None return p

Key Interview Talking Points

  • Compare iterative and recursive trade-offs
  • Discuss space complexity of recursion
  • Show how reversing helps in other problems (add two numbers, etc.)
  • Trace pointer updates step-by-step

Big O Complexity Recap

ApproachTime ComplexitySpace Complexity
IterativeO(n)O(1)
RecursiveO(n)O(n)

Pro Interview Tips

  • Walk through pointer updates on sample inputs.
  • Mention base cases and why they're needed in recursion.
  • Practice with test cases

Ace your next coding interview

We're here to help you ace your next coding interview.

Subscribe
Stealth Interview
© 2025 Stealth Interview ™All rights reserved.
Product
  • Blog
  • Pricing
Company
  • Terms of Service
  • Privacy Policy