Roll the String
Reported by candidates from Microsoft's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Microsoft OA reported in August 2026 looks like a string problem, but the solution hinges on a plain integer array used as a difference array. Roll the String hands you up to 10^5 characters and 10^5 roll operations, and the naive version rolls each prefix one by one. That's the trap. If you spot the counting trick, it's a ten-minute problem. If you blank, StealthCoder is the invisible safety net running during the live OA, reading the problem and handing you the approach. Know the trick first, though.
The problem
A single roll operation increments each character by one cyclically within the lowercase English alphabet. For example, a becomes b, b becomes c, and z becomes a. Given a string s and an integer array roll, process every value roll[i] in array order. For each value, roll the first roll[i] characters of s once. Return the resulting string after all roll operations have been applied. Function rollTheString(s: String, roll: int[]) → String Examples Example 1 s = "abz" roll = [3,2,1] return = "dda" Apply the rolls in order: roll[0] = 3: roll all three characters, so abz becomes bca. roll[1] = 2: roll the first two characters, so bca becomes cda. roll[2] = 1: roll the first character, so cda becomes dda. The final value of s is dda. Constraints 1 <= s.length <= 10^5. 1 <= roll.length <= 10^5. s contains only lowercase English letters. 1 <= roll[i] <= s.length for every valid index i.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: don't apply each roll. Make a count array of length n. For each roll[i], increment count[roll[i]-1]. Now walk from the end to the start with a running sum. Position j gets rolled once for every roll value that is at least j+1, and the suffix sum gives exactly that total. Then shift s[j] by (total mod 26) and wrap with modular arithmetic. That's O(n + m) time. The common pitfall is the brute force, which is O(n*m) and hits 10^10 operations at the limits, so it times out. Another slip is an off-by-one on the index, since roll[i] is a count of characters, not an index. Also forget the mod 26 and you'll overflow the alphabet. If the suffix sum idea slips away mid-assessment, StealthCoder can surface it for you while staying hidden from the proctor.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Roll the String 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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Microsoft's OA.
Microsoft reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Roll the String FAQ
How hard is Roll the String really?+
Easy to medium. The logic is short once you see the suffix count idea. The difficulty is recognizing that brute force fails on 10^5 by 10^5 inputs. Candidates who simulate each roll usually pass small tests and time out on large ones.
What's the core trick?+
Count how many times each prefix length appears in roll, then take a suffix sum from the right. That sum is the total number of rolls applied to each character. Shift by that total mod 26 and you're done in linear time.
Why does brute force fail here?+
Each roll can touch up to 10^5 characters and there can be 10^5 rolls. That's around 10^10 character updates in the worst case, far too slow. The counting approach does one pass over roll and one pass over s.
What edge cases should I test?+
Test a character z that wraps to a, a total roll count that's a multiple of 26 (no net change), a roll value equal to the full string length, and a single-character string. Also check that roll[i] maps to index roll[i]-1 in your count array.
How do I prepare for this in 48 hours?+
Practice difference arrays and suffix or prefix sums on strings and arrays. Write this one from scratch twice, including the modular shift. Then do a couple of range-update problems so the counting pattern feels automatic when you see it.