FastPrepApply a Sequence of Array Rotations
Problems/Apply a Sequence of Array Rotations

Apply a Sequence of Array Rotations

Microsoft logoMicrosoft● MediumINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Rotating an array was the topic of the single medium coding question in a Microsoft software engineering internship interview, described in a review. The first array was rotated as directed by the numbers in a second array, and a faster solution was asked for afterwards.

The review does not say which way a value rotates, what a negative value means, or give limits. Here the values are applied in turn, a positive value rotates right, a negative value rotates left by its size, 0 leaves the array unchanged, and you return the final array. The array has 1 to 2000 values, there are 1 to 10^4 rotations, and every value is between -10^9 and 10^9. The request for a faster solution is not tested separately. The editorial shows the faster method.

Our version is about 75% the same as the reported question.

You are given an integer array nums and an integer array rotations. Apply the rotations to nums one after another, in order:

  • a positive value r rotates the array right by r steps (each step moves the last element to the front);
  • a negative value r rotates the array left by -r steps (each step moves the first element to the end);
  • 0 leaves the array unchanged.

Return the array after all the rotations.

Function

applyRotations(nums: int[], rotations: int[]) → int[]

Examples

Example 1

nums = [1,2,3,4,5]rotations = [2]return = [4,5,1,2,3]

Rotating right by 2 moves the last two elements to the front: [4, 5, 1, 2, 3].

Example 2

nums = [1,2,3,4,5]rotations = [1,-3,7]return = [1,2,3,4,5]

Right by 1 gives [5, 1, 2, 3, 4]. Left by 3 gives [3, 4, 5, 1, 2]. Right by 7 is the same as right by 2, because 5 steps bring the array back to where it was, so it gives [1, 2, 3, 4, 5]. In total the array moved 1 - 3 + 7 = 5 steps right, one full turn.

Example 3

nums = [10,20,30]rotations = [-1,-1]return = [30,10,20]

Left by 1 gives [20, 30, 10], and left by 1 again gives [30, 10, 20].

Constraints

  • 1 <= nums.length <= 2000
  • -10^9 <= nums[i] <= 10^9
  • 1 <= rotations.length <= 10^4
  • -10^9 <= rotations[j] <= 10^9

More Microsoft Onsite Interview questions

  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
  • Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Expected Value of Modified DiceJane Street · ONSITE INTERVIEWJane Street interview questions
  • Reservoir Sampling with Recorded DrawsMeta · ONSITE INTERVIEWMeta interview questions
  • Group-Relative Policy AdvantagesAmazon · ONSITE INTERVIEW
  • Reservoir Sampling with Recorded DrawsStackAdapt · ONSITE INTERVIEWStackAdapt interview questions
  • Sliding-Window Averages as Reduced FractionsCoinbase · ONSITE INTERVIEWCoinbase interview questions
  • Generate Unique Random NumbersGoogle · ONSITE INTERVIEWGoogle interview questions
  • K-Means Delivery ZonesDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
  • Moving Cost by Volume and CategoryWayfair · ONSITE INTERVIEWWayfair interview questions
  • Tensor-Parallel MLP GradientsOpenAI · ONSITE INTERVIEWOpenAI interview questions
  • Vectorized K-Means AssignmentsSambaNova Systems · ONSITE INTERVIEWSambaNova Systems interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public int[] applyRotations(int[] nums, int[] rotations) {
        // Write your code here.
    }
}
Checking account…