Back to Practice
#0062

Reverse a Linked List

MediumDSA25 min20 XP

Problem

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

Why This Matters

Linked lists are about references, not array indices. This problem checks whether you can rewire nodes without losing the rest of the list.

Function Signature

def reverse_list(head):

Examples

Example 1
Input1 -> 2 -> 3 -> 4
Output4 -> 3 -> 2 -> 1

Each node should point to the node that used to be before it.

Constraints

  • Return None for an empty list.
  • Do not create a new list of values as the final answer.
  • Preserve every original node.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Four nodes
Input1 -> 2 -> 3 -> 4
Expected4 -> 3 -> 2 -> 1

The old tail becomes the new head.

Hidden Test Categories
Empty listSingle nodeTwo nodes