Left Rotations of an Array

You are given an array consisting of N elements and need to perform Q queries on that array. Each query consists of an integer indicating the number of elements by which the array should be left rotated. For each query, return the final array obtained after performing the left rotations.

Input:

1. The first line contains an integer 'T', representing the number of test cases.
2. Each test case starts with a line containing two space-separated integers 'N' and 'Q', denoting the number of elements in the array and the number of queries, respectively.
3. The following line contains 'N' space-separated integers representing the array elements.
4. The next line contains 'Q' integers representing each query.

Output:

For each query of each test case, return 'N' space-separated integers representing the array after the left rotations.

Example:

Input:
Array: [1, 2, 3, 4, 5, 6]
Queries: {2, 4, 1}

Outputs:
For query 1 (rotate by 2): [3, 4, 5, 6, 1, 2]
For query 2 (rotate by 4): [5, 6, 1, 2, 3, 4]
For query 3 (rotate by 1): [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:

Perform each query on the original array only, ensuring every output corresponds to its initial state.
You don't need to print anything, just implement the function.
AnswerBot
4mo

Perform left rotations on an array based on given queries.

  • Create a function that takes the array, number of elements, number of queries, and the queries as input.

  • For each query, rotate the array by th...read more

Help your peers!
Select
Add answer anonymously...

Tech Vedika Software Engineer interview questions & answers

A Software Engineer was asked Q. What are some basic questions you were asked about JavaScript?
A Software Engineer was asked Q. Left Rotations of an Array You are given an array consisting of N elements and n...read more
A Software Engineer was asked Q. Ways To Make Coin Change Given an infinite supply of coins of varying denominati...read more

Popular interview questions of Software Engineer

A Software Engineer was asked Q1. What are some basic questions you were asked about JavaScript?
A Software Engineer was asked Q2. Left Rotations of an Array You are given an array consisting of N elements and n...read more
A Software Engineer was asked Q3. Ways To Make Coin Change Given an infinite supply of coins of varying denominati...read more
Tech Vedika 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