Asked inAxtria,Analyst
Rotate array

Given an array with N elements, the task is to rotate the array to the left by K steps, where K is non-negative.

Input Format:

The first line contains an integer N representing the size of the array.

The second line contains N space-separated integers representing the elements of the array.

The last line contains an integer K representing the number of times the array has to be rotated in the left direction. 

Output Format:

The only line of the output prints N space-separated integers representing the Rotated array elements.
Constraints:
1 <= N <= 10^3
1 <= arr[i] <= 10^9
1 <= K < N
CodingNinjas
author
2y
Optimised Approach
  • We note that rotating an Array K times is just placing the first K elements at the end and bringing forward rest of the elements.
  • So we store the first K elements in a temporary array...read more
CodingNinjas
author
2y
Naive Approach
  • We rotate the array K times where in each iteration we rotate the array by 1.
  • Rotating the array once can be done by changing input[i] to input[i+1] and appending the first character to t...read more
Help your peers!
Add answer anonymously...
Axtria Analyst Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter