#K38642. Left Rotate Array

    ID: 26244 Type: Default 1000ms 256MiB

Left Rotate Array

Left Rotate Array

Given an array (arr[]) of size (n) and an integer (k), perform a left rotation on the array by (k) positions. In a left rotation, each element of the array shifts one unit to the left and the first element moves to the end of the array. Mathematically, for each index (i) in the array, its new position becomes ((i - k) \mod n).

For example, if (arr = [1, 2, 3, 4, 5]) and (k = 2), after one rotation the array becomes ([2, 3, 4, 5, 1]), and after two rotations it becomes ([3, 4, 5, 1, 2]).

inputFormat

The first line contains an integer (n), the number of elements in the array. The second line contains (n) space-separated integers representing the elements of the array. The third line contains an integer (k), the number of left rotations to perform.

outputFormat

Output a single line containing the rotated array as space-separated integers.## sample

5
1 2 3 4 5
2
3 4 5 1 2