#848
Shifting Letters
specialist · 930 · lc medium +32 · verified · 46.1% accepted · 1,549 likes · top 30%
Description
You are given a string s of lowercase English letters and an integer array shifts of the same length.
The shift() operation on a letter advances it to the next letter in the alphabet, with 'z' wrapping back to 'a'.
- For example, shift('a') = 'b', shift('t') = 'u', and shift('z') = 'a'.
For each shifts[i] = x, apply shift() exactly x times to each of the first i + 1 characters of s.
Return the final string after all shifts are applied.
Example 1:
Input: s = "abc", shifts = [3,5,9]
Output: "rpl"
Explanation: We start with "abc".
After shifting the first 1 letters of s by 3, we have "dbc".
After shifting the first 2 letters of s by 5, we have "igc".
After shifting the first 3 letters of s by 9, we have "rpl", the answer.
Example 2:
Input: s = "aaa", shifts = [1,2,3]
Output: "gfd"
Code
1
2
3