From 43b4cbdb4da31fc65620e7734e6c55044a2ccfc1 Mon Sep 17 00:00:00 2001 From: durva439 <58338014+durva439@users.noreply.github.com> Date: Thu, 21 Oct 2021 13:42:19 +0530 Subject: [PATCH] Add files via upload Rotated Array by durva439 --- RotatedArray.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 RotatedArray.py diff --git a/RotatedArray.py b/RotatedArray.py new file mode 100644 index 0000000..2f95f55 --- /dev/null +++ b/RotatedArray.py @@ -0,0 +1,21 @@ +def rotateArray(arr, n, d): + temp = [] + i = 0 + while (i < d): + temp.append(arr[i]) + i = i + 1 + i = 0 + while (d < n): + arr[i] = arr[d] + i = i + 1 + d = d + 1 + arr[:] = arr[: i] + temp + return arr + +arr = [1, 2, 3, 4, 5, 6, 7] +print("Array after left rotation is: ", end=' ') +print(rotateArray(arr, len(arr), 2)) + + +########################### +Output : Array after left rotation is: [3, 4, 5, 6, 7, 1, 2] \ No newline at end of file