Arrays · 20 / 23 Exercise Medium

Rotate a list

Objective

Rotating a list k positions to the right means the last k elements move to the front. Slicing lets you do it without loops.

Instructions

  • Read a line of space-separated items and then an integer k (it may be larger than the length).
  • Show the list rotated k positions to the right, with the items separated by spaces. If the list is empty, show an empty line.
Input
1 2 3 4 5
2
Output
4 5 1 2 3

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise