Problem · String
Roll the String
Learn this problemProblem 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.