Right rotation
Input
rotate_list([1, 2, 3, 4, 5], 2)
Output
[4, 5, 1, 2, 3]
Each element moves two positions to the right; the last two wrap to the front.
Full lesson preview
Rotate a list by n positions. Positive n rotates to the right, negative n rotates to the left.
Problem statement
Task
Examples
Input
rotate_list([1, 2, 3, 4, 5], 2)
Output
[4, 5, 1, 2, 3]
Each element moves two positions to the right; the last two wrap to the front.
Input format
Output format
Constraints
Samples
Input
rotate_list([1, 2, 3], -1)
Output
[2, 3, 1]
Negative n rotates left by 1.