dsa · medium
Rotate List
GreyOrangeLinked List
Rotate value-list head to the **right** by k. Return the values.
Arguments
head— the linked list, given as a Python list of node valuesk— how many places to rotate the list right
**Example:** [1,2,3,4,5], k=2 → [4,5,1,2,3].
Constraints
0 <= length <= 500 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: [1,2,3,4,5] 2 Expected: [4,5,1,2,3]
Example 2
Input: [0,1,2] 4 Expected: [2,0,1]