Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Left rotation in O(n) #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Left Rotation/Bhavesh Mangnani/left_rotation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/python3

import math
import os
import random
import re
import sys

#
# Complete the 'rotateLeft' function below.
#
# The function is expected to return an INTEGER_ARRAY.
# The function accepts following parameters:
# 1. INTEGER d
# 2. INTEGER_ARRAY arr
#

def rotateLeft(d, arr):
# Write your code here
n = len(arr)
start = d%n
ans =[]
for i in range(n):
ans.append(arr[start])
start=(start+1)%n
return ans

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])

arr = list(map(int, input().rstrip().split()))

result = rotateLeft(d, arr)

fptr.write(' '.join(map(str, result)))
fptr.write('\n')

fptr.close()