// string = "aaa"
// After Shifting the first 1 letter by 1 = "baa"
// After shifting the first 2 letters by 2 = "dca"
// After shifting the first 3 letters 3 = "gfd"
// result = "gfd"
public class Program {
static String shifLetters(String str, int[] shifts) {
int size = shifts.length;
char[] arr = str.toCharArray();
for (int i = size - 1; i >= 0; i--) {
if (i + 1 < size) {
shifts[i] += shifts[i + 1];
}
shifts[i] = shifts[i] % 26;
int asciicode = str.charAt(i) - 'a';
asciicode = asciicode + shifts[i];
if (asciicode > 25) {
asciicode = asciicode - 26;
}
arr[i] = (char)('a' + asciicode);
}
return new String(arr);
}
public static void main(String[] args) {
String str = "aaa";
int[] shifts = {1, 2, 3};
str = shifLetters(str, shifts);
System.out.print(str);
}
}
/*
run:
gfd
*/