Programming Basic

Problem - 4808

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. (Follow up: Could you do it in one pass?)

Example 1:

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

Output: [1,4,3,2,5]

Reasoning: 2 - 4 is [2,3,4]. We want to reverse it in place [4,3,2]. We do not modify the linked list elsewhere, giving us the final [1,4,3,2,5]

Example 2:

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

Output: [5]

 


The solution for this problem is available for $0.99. You can also purchase a pass for all available solutions for $99.

report an error