Reverse Linked List II
Given the head of a singly linked list and two integers left and right, reverse the nodes of the list from position left to position right.
Return the reversed linked list.
Example 1
Input
head = [1,2,3,4,5] left = 2 right = 4
Output
[1,4,3,2,5]
Explanation
The nodes from position 2 to position 4 are [2,3,4]. Reversing them gives [4,3,2].
Example 2
Input
head = [5] left = 1 right = 1
Output
[5]
Explanation
The selected portion contains only one node, so the linked list remains unchanged.
Constraints
Hints:
Hint 1
Use a pointer to reach the node immediately before position left.
Hint 2
Reverse the selected portion in-place and reconnect it with the unchanged parts of the list.
Author & Technical Reviewer
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Aug 18, 2026
Last updated
Aug 18, 2026
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output