Geeksforgeeks

Error

Given an array of size **N**. The task is to rotate array by **D** elements where **D **≤ **N**.

**Example 1:**

**Input:
**N = 7
Arr[] = {1, 2, 3, 4, 5, 6, 7}
D = 2
**Output:** 3 4 5 6 7 1 2
**Explanation:**
Rotate by 1: [2, 3, 4, 5, 6, 7, 1]
Rotate by 2: [3, 4, 5, 6, 7, 1, 2]

**Example 2:**

**Input:
**N = 4
Arr[] = {1, 3, 4, 2}
D = 3
**Output:** 2 1 3 4

**Your Task:**

You don't need to read input or print anything. Your task is to complete the function **leftRotate()** which takes the array of integers **arr[], **its size **n** and **d **as input parameters and rotates arr[] in-place without using any extra memory.

**Expected Time Complexity:** O(N)

**Expected Auxiliary Space:** O(1)

**Constraints:**

1 ≤ N ≤ 10^{5}

1 ≤ Arr[i] ≤ 1000

0 ≤ D ≤ N

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Rotating an Array

...