Left rotation in array interview preparation
#!/bin/python3
import math
import os
import random
import re
import sys
#
# Complete the 'rotLeft' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts following parameters:
# 1. INTEGER_ARRAY a
# 2. INTEGER d
#
def rotLeft(a, d):
# Write your code here
temp=[]
i=0
while i<d:
temp.append(a[i])
i=i+1
i=0
while d<len(a):
a[i]=a[d]
i=i+1
d=d+1
a[:]=a[:i]+temp
return a
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
d = int(first_multiple_input[1])
a = list(map(int, input().rstrip().split()))
result = rotLeft(a, d)
fptr.write(' '.join(map(str, result)))
fptr.write('\n')
fptr.close()
Comments
Post a Comment
If you have any doubt you ask me in comment section