class Solution {
public String shiftingLetters(String S, int[] shifts) {
int n = shifts.length;
int prev = 0;
char[] arr = S.toCharArray();
for (int i = n - 1; i >= 0; i--) {
prev += shifts[i] % 26;
arr[i] = getNextChar(arr[i], prev);
}
return new String(arr);
}
public char getNextChar(char a, int diff) {
return (char)((((a - 'a') + diff) % 26) + 'a');
}
}
Categories