Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

Given an array **arr[] **of size **N** and an integer **K**, the task is to left rotate the array **K** indexes

**Example 1:**

**Input: **N = 7, K = 2
arr[] = {1, 2, 3, 4, 5, 6, 7}
**Output:** 3 4 5 6 7 1 2
**Explanation**: Rotation of the above
array by 2 will make the output array .

**Example 2:**** **

**Input: **N = 6, K = 12
arr[] = {1, 2, 3, 4, 5, 6}
**Output:** 1 2 3 4 5 6

**Your Task:**

This is a function problem. You don't need to take any input, as it is already accomplished by the driver code. You just need to complete the function **leftRotate**() that takes array** arr, **integer** K **and integer** N** as parameters and rotate the given array by d value.

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

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

**Constraints:**

1 ≤ N ≤ 10^{5}

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...

Quick Left Rotation

...