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
2y

The question seems to be gibberish and does not make sense.

  • I'm sorry, but I don't understand the question.

  • Could you please repeat or rephrase the question?

  • I am not able to provide an answer to this qu...read more

Help your peers!
Select
Add answer anonymously...

Digital Web Analytics and Optimization Software Developer interview questions & answers

A Software Developer was asked Q. Left Rotations of an Array Given an array of size N and Q queries, each query re...read more
A Software Developer was asked Q. Prime Numbers Identification Given a positive integer N, your task is to identif...read more
A Software Developer was asked Q. Integer to Roman Conversion Given an integer N, convert it to its corresponding ...read more

Popular interview questions of Software Developer

A Software Developer was asked Q1. Left Rotations of an Array Given an array of size N and Q queries, each query re...read more
A Software Developer was asked Q2. Prime Numbers Identification Given a positive integer N, your task is to identif...read more
A Software Developer was asked Q3. Integer to Roman Conversion Given an integer N, convert it to its corresponding ...read more
Digital Web Analytics and Optimization 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