You are given the head of a linked list and two integers m and n, write a program to reverse the linked list from position m to n, both inclusive.

Problem Note:

  • It is guaranteed that 1 ≤ m ≤ n ≤ length of linked list
  • Do not use extra space. Do this in-place and in one iteration.

Example 1

Input: 2->4->6->8->10, m = 2, n = 4
Output: 2->8->6->4->10

Example 2

Input: 2->3->7->9->23, m = 1, n = 5
Output: 23->9->7->3->2

Example 3

Input: 10->20->2->5->9->8, m = 3, n = 3
Output: 10->20->2->5->9->8