Given an array of integers and a number,
perform left rotations on the array.
Then print the updated array as a single line
of space-separated integers.
Sample Input
5 4
1 2 3 4 5
Sample Output:
5 1 2 3 4
Explanation
When we perform d=4 left rotations,
the array undergoes the following
sequence of changes:
Thus, we print the array's final state as a single line of
space-separated values, which is 5 1 2 3 4.
Solution:
import math
import os
import random
import re
import sys
if __name__ == '__main__':
nd = input().split()
n = int(nd[0])
d = int(nd[1])
a = list(map(int, input().
rstrip().split()))
for j in range(0,d):
f=a[0]
for i in range(len(a)-1):
a[i]=a[i+1]
a[len(a)-1]=f
for k in range(len(a)):
print(a[k],end=" ")
0 Comments