Loading content...
You are given a string s consisting of lowercase English letters and an integer array rotations of the same length as the string.
A rotation operation on a letter advances it forward in the alphabet by one position, with wraparound behavior such that 'z' becomes 'a'.
For example:
The rotation array defines cumulative rotation operations: for each position i in the array, you must rotate all characters from index 0 to index i (inclusive) by rotations[i] positions forward.
More specifically:
rotations[0], rotate the first character by rotations[0] positions.rotations[1], rotate the first two characters by rotations[1] positions.rotations[i], rotate the first i + 1 characters by rotations[i] positions.Return the final transformed string after applying all rotation operations in sequence.
Key Insight: Each character at position i is affected by rotations at indices i, i+1, i+2, ..., n-1. This means the total rotation for character at index i equals the sum of rotations[i] + rotations[i+1] + ... + rotations[n-1].
s = "abc"
rotations = [3,5,9]"rpl"Starting with "abc": • After rotating first 1 character by 3: 'a' → 'd', giving "dbc" • After rotating first 2 characters by 5: 'd' → 'i', 'b' → 'g', giving "igc" • After rotating first 3 characters by 9: 'i' → 'r', 'g' → 'p', 'c' → 'l', giving "rpl" Alternatively, character at index 0 is rotated by 3+5+9=17, character at index 1 by 5+9=14, character at index 2 by 9.
s = "aaa"
rotations = [1,2,3]"gfd"Character at index 0: 'a' rotated by 1+2+3=6 → 'g' Character at index 1: 'a' rotated by 2+3=5 → 'f' Character at index 2: 'a' rotated by 3 → 'd' Result: "gfd"
s = "xyz"
rotations = [1,1,1]"aaa"Character at index 0: 'x' rotated by 1+1+1=3 → 'a' (x→y→z→a) Character at index 1: 'y' rotated by 1+1=2 → 'a' (y→z→a) Character at index 2: 'z' rotated by 1 → 'a' (z→a) Result: "aaa" This demonstrates the wraparound behavior from 'z' to 'a'.
Constraints