Simple Array Rotation Game
Reported by candidates from Snowflake's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Snowflake reported this one in June 2026, and it looks like a toy problem until you read the constraints. The title says rotation game, but the real task is one index lookup per query. Find where the max sits in the original array, then do modular arithmetic for each rotation count. n and m go up to 500000, and rotation values go up to 10^9, so any loop that actually rotates the array will time out. If you blank on the math during the OA, StealthCoder is the safety net running invisibly on your screen. Here's the shape of the answer.
The problem
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 getMaxRotationIndexes(a: int[], rotations: int[]) → int[] 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. Examples Example 1 a = [1, 2, 3] rotations = [1, 2, 3] return = [1, 0, 2] 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 1 ≤ n, m ≤ 500000 1 ≤ a[i] ≤ 10^9 0 ≤ rotations[i] ≤ 10^9
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: find the index p of the max element once, in O(n). After k left rotations, an element at original index p lands at (p - k) mod n. Each query is then O(1), so the total is O(n + m). The classic pitfall is simulating rotations, which costs O(n*m) and dies at 500000 each. The second pitfall is the modulo itself. In languages like C++ or Java, (p - k) % n can go negative, so use ((p - k) % n + n) % n. Reduce k mod n first, since k can reach 10^9. Check against the example: a = [1,2,3], p = 2, n = 3. k=1 gives 1, k=2 gives 0, k=3 gives 2. That matches. Elements are distinct, so the max is unique. If the live OA freezes you, StealthCoder can hand you this formula and the modulo fix in seconds.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Simple Array Rotation Game cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Snowflake's OA.
Snowflake reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Simple Array Rotation Game FAQ
What's the trick in the Snowflake array rotation problem?+
Don't rotate anything. Find the index of the max once, then for each rotation count k compute (p - k) mod n, where p is the max's original index. That turns an O(n*m) simulation into O(n + m), which is what the 500000 limits demand.
How hard is this problem really?+
Easy once you see the formula, easy to fail if you simulate. The logic is one line, but the constraints punish brute force. Most of the difficulty is spotting that rotations are not cumulative and that the max's position is the only thing that matters.
Why do negative modulo results matter here?+
Left rotation moves the element toward index 0, so you subtract k from p. That can go below zero before wrapping. In C++, Java, and JavaScript the % operator keeps the sign, so normalize with ((p - k) % n + n) % n. Python handles it for you.
Are the rotations cumulative?+
No. Each rotation value applies to the original array, not to the result of the previous query. The example confirms it: [1,2,3] rotated by 1, 2, and 3 each start from [1,2,3]. So every query is independent and you can answer them in any order.
How do I prepare for this in 48 hours?+
Practice index-mapping problems: circular arrays, rotate array, and modular wraparound. Write the formula from memory, then test edge cases: k = 0, k = n, k much larger than n, and n = 1. Also confirm you're returning an array of indexes, not values.