Reverse Linked List

EasyLinked ListFree to try
Asked byAmazonMicrosoftAppleBloombergFacebookGoogle

Problem

Given the head of a singly linked list, reverse the list in place and return the new head.

Examples

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

Constraints

  • The number of nodes is in the range [0, 5000].

Try it now — no sign-up needed. Write your solution in Python or JavaScript, run it against test cases, and submit for a verdict, right in your browser.

Open the editor →

How to approach it: the Linked List pattern

A chain of nodes, each pointing to the next. No random access like an array, but insertion and deletion at a known position is O(1), and many classic problems come down to careful pointer rewiring.

Look for this pattern when

  • The problem explicitly gives you a linked list (reverse it, merge lists, detect a cycle, reorder it).
  • You need O(1) insertion/deletion without shifting elements, unlike an array.

Read the full Linked List guide →

Video walkthroughs

Original problem on LeetCode ↗

More Linked List problems