Loading...
Loading...
Loading...
Rotate a linked list to the right by k places: the last k nodes move to the front in the same order. Print the result. k may be larger than the length of the list.
Example
Input
1 2 3 4 5 2
Output
4 5 1 2 3
Try the problem first. Open one hint at a time.
Count the nodes and keep the last one. Use k % length.
Link the last node to the head, then cut the ring at the right place.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor