From 8d6351104547658c88a565349e1fc8d1b06e18ab Mon Sep 17 00:00:00 2001 From: Bhavesh Mangnani Date: Tue, 20 Oct 2020 17:01:02 +0530 Subject: [PATCH] left rotation in O(n) --- .../Bhavesh Mangnani/left_rotation.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Left Rotation/Bhavesh Mangnani/left_rotation.py diff --git a/Left Rotation/Bhavesh Mangnani/left_rotation.py b/Left Rotation/Bhavesh Mangnani/left_rotation.py new file mode 100644 index 0000000..bf01e34 --- /dev/null +++ b/Left Rotation/Bhavesh Mangnani/left_rotation.py @@ -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()