Roll the String
Updated
Problem statement
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[]) → StringExamples
Example 1
s = "abz"roll = [3,2,1]return = "dda"Apply the rolls in order:
roll[0] = 3: roll all three characters, soabzbecomesbca.roll[1] = 2: roll the first two characters, sobcabecomescda.roll[2] = 1: roll the first character, socdabecomesdda.
The final value of s is dda.
Constraints
1 <= s.length <= 10^5.1 <= roll.length <= 10^5.scontains only lowercase English letters.1 <= roll[i] <= s.lengthfor every valid indexi.
More Microsoft Online Assessment questions
- Maximum Score with Prime JumpsOA · Seen Dec 2026
- Minimum Non-Adjacent Selection CapabilityOA · Seen Dec 2026
- Authentication SystemOA · Seen Nov 2026
- Maximum String OperationsOA · Seen Nov 2026
- Minimum Cost to Process Priority TasksOA · Seen Nov 2026
- Most Visited Sprint MarkerOA · Seen Nov 2026
- Maximum Escape Game ScoreOA · Seen Nov 2026
- Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
- Maximum Interactive Team SizeOA · Seen Nov 2026
- Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026
Similar questions at other companies
- Earliest Time to Schedule a MeetingMathWorks · OAMathWorks interview questions
- Earliest Meeting Start on a 24-Hour ClockIMC Trading · OAIMC Trading interview questions
- Stars Between Bars in RangesExpedia · OAExpedia interview questions
- Prefix-Length Letter ShiftsChewy · PHONE SCREEN
- Count Lamps Lighting Each PointAirbnb · OAAirbnb interview questions
- Count One-Swap Number PairsCapital One · OACapital One interview questions
- Find a String Within One Mismatch of AllBarclays · OABarclays interview questions
- Maximum Game Score with Fixed Forward JumpsStripe · OAStripe interview questions
- Count Subarrays Matching a Comparison PatternTikTok · OATikTok interview questions
- Split a Matrix Into Four Partitions by Average (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
Microsoft interview experiences
- Microsoft OA Questions, October 2026: 4 Experiences
- Microsoft Experienced SWE Phone Screen: 1 Experience
- 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)