Skip to content

Instantly share code, notes, and snippets.

@ammarshaikh123
Created May 27, 2019 11:42
Show Gist options
  • Save ammarshaikh123/b8408b333214dcdbc8684904b0e818d3 to your computer and use it in GitHub Desktop.
Save ammarshaikh123/b8408b333214dcdbc8684904b0e818d3 to your computer and use it in GitHub Desktop.
A left rotation operation on an array shifts each of the array's elements unit to the left. For example, if left rotations are performed on array , then the array would become . Given an array of integers and a number, , perform left rotations on the array. Return the updated array to be printed as a single line of space-separated integers. Func…
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the rotLeft function below.
def rotLeft(a, d):
n=0
while(n!=d):
n=n+1
temp=a[0]
a[:-1]=a[1:]
a[len(a)-1]=temp
return a
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
nd = input().split()
n = int(nd[0])
d = int(nd[1])
a = list(map(int, input().rstrip().split()))
result = rotLeft(a, d)
fptr.write(' '.join(map(str, result)))
fptr.write('\n')
fptr.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment