Created
May 27, 2019 11:42
-
-
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…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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