Rotate right by 2
Input
rotate_list([1,2,3,4,5], 2)
Output
[4, 5, 1, 2, 3]
Elements move two positions to the right.
Full lesson preview
Rotate elements of a list to the right by k positions (negative k rotates left).
Problem statement
Task
Examples
Input
rotate_list([1,2,3,4,5], 2)
Output
[4, 5, 1, 2, 3]
Elements move two positions to the right.
Input format
Output format
Constraints
Samples
Input
rotate_list([1,2,3,4], -1)
Output
[2, 3, 4, 1]
Negative k rotates left by 1.