Reverse Linked List - Problem

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

A singly linked list is a data structure where each node contains a value and a reference to the next node in the sequence. Reversing the list means changing the direction of all pointers so that the last node becomes the first, and the first node becomes the last.

Input & Output

Example 1 — Basic List
$ Input: head = [1,2,3,4,5]
Output: [5,4,3,2,1]
💡 Note: The linked list 1→2→3→4→5 becomes 5→4→3→2→1 after reversing all the pointer directions.
Example 2 — Two Nodes
$ Input: head = [1,2]
Output: [2,1]
💡 Note: Simple case with two nodes: 1→2 becomes 2→1.
Example 3 — Empty List
$ Input: head = []
Output: []
💡 Note: An empty list remains empty after reversal.

Constraints

  • The number of nodes in the list is the range [0, 5000]
  • -5000 ≤ Node.val ≤ 5000

Visualization

Tap to expand
Reverse Linked List: Transform Pointer DirectionsOriginal List:12345Reverse Process:Change all arrow directions ↔Reversed List:54321
Understanding the Visualization
1
Input
Original linked list: 1→2→3→4→5
2
Process
Reverse all pointer directions
3
Output
Reversed linked list: 5→4→3→2→1
Key Takeaway
🎯 Key Insight: Use three pointers to safely reverse each link without losing the rest of the list
Asked in
Amazon 85 Microsoft 72 Google 68 Apple 45 Facebook 42
1.3M Views
Very High Frequency
~15 min Avg. Time
15.4K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen