Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Reverse a list recursively

Reverse a singly linked list using a recursive approach.

Python practice14 minLinked ListsIntermediateLast updated March 27, 2026

Problem statement

Given the head of a singly linked list, reverse the list using recursion and return the head of the reversed list. The reversal must be done by rearranging pointers. For an empty list, return None.

Task

Use recursion to reverse a singly linked list and return the new head.

Examples

Recursive reversal

Input

head = [1, 2, 3]

Output

[3, 2, 1]

Using recursion, reverse pointers so the list becomes [3 -> 2 -> 1].

Input format

A linked list represented by its head node. Use create_linked_list([...]) to build test inputs.

Output format

Return the head node of the reversed linked list. Tests convert the returned head to a Python list.

Constraints

- Do the reversal by adjusting next pointers; do not allocate new nodes. - Recursive depth will be at most the length of the list. - Aim for O(n) time and O(n) call stack for recursion.

Samples

Sample 1

Input

[4, 3, 2, 1]

Output

[1, 2, 3, 4]

Recursively reverse the list to get the correct result.