Given the head of a linked list, rotate the list to the right by k places. Input is given as an array representation of the linked list and an integer k.
Example 1
Input: head = [1,2,3,4,5], k = 2
Output: [4,5,1,2,3]
Explanation: Rotating right once gives [5,1,2,3,4]. Rotating a second time gives [4,5,1,2,3].
Example 2
Input: head = [0,1,2], k = 4
Output: [2,0,1]
Explanation: The list has 3 nodes, so rotating by 4 is the same as rotating by 4 mod 3 = 1. Moving the last node to the front gives [2,0,1].
Example 3
Input: head = [1,2,3], k = 3
Output: [1,2,3]
Explanation: Rotating a 3-node list by 3 brings it back to where it started.
If we close the list into a circle first, picking a rotation just means choosing where to break the circle. The whole task becomes: find the new tail and snip there.
Run checks all cases above. Submit evaluates all test cases.