Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Reverse a list iteratively

Reverse a singly linked list using an iterative in-place algorithm.

Python practice13 minLinked ListsIntermediateLast updated March 27, 2026

Problem statement

Given the head of a singly linked list, reverse the list in-place using an iterative approach and return the head of the reversed list. You must not allocate new nodes; change the next pointers to reverse the list. If the list is empty, return None.

Task

Implement an iterative algorithm to reverse a singly linked list and return the new head.

Examples

Simple example

Input

head = [1, 2, 3]

Output

[3, 2, 1]

Reversing the list [1 -> 2 -> 3] yields [3 -> 2 -> 1].

Input format

A linked list represented by its head node. Use the provided create_linked_list([...]) helper to construct lists in tests.

Output format

Return the head node of the reversed linked list. In tests we convert it to a Python list for comparison.

Constraints

- The list length can be 0 or more. - You must reverse links in-place (O(1) extra space). - Time complexity should be O(n).

Samples

Sample 1

Input

[1, 2, 3, 4]

Output

[4, 3, 2, 1]

Iteratively reverse the links to produce the reversed list.