Left Rotations of an Array

Given an array of size N and Q queries, each query requires left rotating the original array by a specified number of elements. Return the modified array for each query.

Input:

The first line contains an integer 'T', denoting the number of test cases. The first line of each test case contains two integers, 'N' and 'Q'. The second line contains 'N' space-separated integers representing the array elements. The third line contains 'Q' space-separated integers representing each query.

Output:

For every query of each test case, return 'N' space-separated integers representing the array after rotation for that query.

Example:

Let array = [1, 2, 3, 4, 5, 6] and queries = {2, 4, 1}. Output for each query is: [3, 4, 5, 6, 1, 2], [5, 6, 1, 2, 3, 4], [2, 3, 4, 5, 6, 1].

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 1000
  • 1 <= Q <= 100
  • 0 <= Queries[i] <= 105
  • -105 <= Array[i] <= 105

Note:

Each query should be processed on the original array.

AnswerBot
4mo

Rotate an array left by a specified number of elements for each query.

  • Iterate through each query and rotate the array left by the specified number of elements using array slicing.

  • Handle cases where th...read more

Help your peers!
Select
Add answer anonymously...
Tech Vedika Software Developer 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