61. Rotate List
Practice Rotate List for free on NudgeCode: Medium, Linked List pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Rotate a linked list to the right by k places: each step moves the last node to the front. Return the head of the rotated list. k can be larger than the length of the list, and an empty list stays empty.
Example
head = [1,2,3,4,5], k = 2 -> [4,5,1,2,3]
head = [0,1,2], k = 4 -> [2,0,1]
Constraints
- 0 <= length of the list <= 500
- -100 <= Node.val <= 100
- 0 <= k <= 2 * 10^9