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.
Be the first one to answer
Add answer anonymously...
Tech Vedika Software Engineer 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

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