Rotate Array Problem Statement

The task is to rotate a given array with N elements to the left by K steps, where K is a non-negative integer.

Input:

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:

The output consists of N space-separated integers representing the rotated array elements.

Example:

Input:
N = 5
array = [1, 2, 3, 4, 5]
K = 2
Output:
[3, 4, 5, 1, 2]

Constraints:

  • 1 <= N <= 103
  • 1 <= arr[i] <= 109
  • 1 <= K < N
AnswerBot
4mo

Rotate a given array to the left by K steps.

  • Create a new array to store the rotated elements.

  • Use modular arithmetic to handle cases where K is greater than the array size.

  • Shift elements to the left by...read more

Help your peers!
Select
Add answer anonymously...

MAQ Software Software Engineer interview questions & answers

A Software Engineer was asked 11mo agoQ. Given a singly linked list, reverse the nodes of the linked list k at a time and...read more
A Software Engineer was asked 12mo agoQ. How does hashing help in identifying duplicate values?
A Software Engineer was asked Q. Given an array, reverse the order of its elements.

Popular interview questions of Software Engineer

A Software Engineer was asked 10mo agoQ1. Given a singly linked list, reverse the nodes of the linked list k at a time and...read more
A Software Engineer was asked 11mo agoQ2. How does hashing help in identifying duplicate values?
A Software Engineer was asked Q3. Given an array, reverse the order of its elements.
MAQ Software Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits