Problems

Array Rotation

EasyArrays100% acceptance

Given an array of integers and a number of positions to rotate, write a program to rotate the array to the right by the given number of positions.

Input:

  • The first line contains the number of elements in the array.
  • The second line contains the elements of the array separated by spaces.
  • The third line contains the number of positions to rotate.

Output:

  • The rotated array, with elements separated by spaces.

Example 1

Input: 5 1 2 3 4 5 2

Output: 4 5 1 2 3

The array is rotated 2 positions to the right.

Constraints

  • 1 <= n <= 10^5
  • 0 <= k <= 10^5

Hints

arraysrotation
Array Rotation | CodeForge AI