Skip to content

Practice Reverse Linked List II

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#92
LeetCode Problem

Reverse Linked List II

Problem Statement

Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list.

Source: Reverse Linked List II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
head = [1,2,3,4,5], left = 2, right = 4
Output
[1,4,3,2,5]

# Example 2

Input
head = [5], left = 1, right = 1
Output
[5]

Constraints

The number of nodes in the list is n.
1 <= n <= 500
-500 <= Node.val <= 500
1 <= left <= right <= n

Related LeetCode Problems

Practice more problems similar to Reverse Linked List II.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.