Rotate List
Given a linked list, rotate it to the right by k places and return the head.
Examples
Input: [[1,2,3,4,5],2]
Output: [4,5,1,2,3]
Input: [[0,1,2],4]
Output: [2,0,1]
Hints
Identify the length of the linked list and adjust k to be k % length to handle cases where k is larger than the list length.
Traverse to the (length - k - 1)th node to find the new tail, then set its next to None and the next node as the new head.
Traverse to the end of the list, connect the last node to the original head to form a cycle, then break the cycle at the new tail to complete the rotation.
Related Problems
Rotate List
Given a linked list, rotate it to the right by k places and return the head.