Rotate the list to the right by k places: the last k nodes move to the front. 1 -> 2 -> 3 -> 4 -> 5 rotated by 2 is 4 -> 5 -> 1 -> 2 -> 3. k can be much larger than the length.
The tests show a list as a Python list of its values: [1, 2, 3] stands for 1 -> 2 -> 3.
Example 1
Input:
rotate_list(head, 2) # head = 1 -> 2 -> 3 -> 4 -> 5
Output:
[4, 5, 1, 2, 3]
Example 2
Input:
rotate_list(head, 4) # head = 0 -> 1 -> 2
Output:
[2, 0, 1]
0 <= number of nodes <= 1000000 <= k <= 10**9No results yet
Run your code to check it against the examples, or submit to run every test.