92. Reverse Linked List II

Practice Reverse Linked List II for free on NudgeCode: Medium, Linked List pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Given the head of a singly linked list and two positions left <= right (1-indexed), reverse the nodes from position left to position right and return the head of the resulting list.

Try to do it in a single pass.

Example

head = [1,2,3,4,5], left = 2, right = 4  ->  [1,4,3,2,5]

Constraints