FastPrepFastPrep
Problem Brief

Simple Array Rotation Game

INTERNOA

You are given an array of distinct positive integers and another array that specifies the number of left circular rotations to be performed.

Rotation Rule:

  • A left circular rotation shifts all elements one position to the left.
  • The element at index 0 moves to the last position.
  • All other elements shift left by one index.

Task:

For each rotation value in the rotations array:

  • Perform the rotation on the original array (not cumulative).
  • Determine the index of the maximum element after the rotation.

Function Description

Complete the function getMaxRotationIndexes.

getMaxRotationIndexes has the following parameters:

  • int a[]: Array of distinct integers.
  • int rotations[]: Array representing the number of rotations.

Returns

int[]: Array where each element represents the index of the maximum element after corresponding rotations.

1Example 1

Input
a = [1, 2, 3], rotations = [1, 2, 3]
Output
[1, 0, 2]
Explanation

For each rotation, the array [1, 2, 3] is rotated starting from the original (not cumulative):

  • Rotation 1 → [2, 3, 1], max = 3 at index 1
  • Rotation 2 → [3, 1, 2], max = 3 at index 0
  • Rotation 3 → [1, 2, 3], max = 3 at index 2

Constraints

Limits and guarantees your solution can rely on.

  • 1 ≤ n, m ≤ 500000
  • 1 ≤ a[i] ≤ 10^9
  • 0 ≤ rotations[i] ≤ 10^9
public int[] getMaxRotationIndexes(int[] a, int[] rotations) {
    // write your code here
}
Input

a

[1, 2, 3]

rotations

[1, 2, 3]

Output

[1, 0, 2]

Sign in to submit your solution.