Medium

Quiz

#92 Reverse Linked List II

APPROACH

Reverse the nodes of singly linked list head from position left to position right inclusive (1-indexed, left <= right) and return the head of the modified list.

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]
1 of 4
1:00

What is the optimal approach for this problem?