You are given a string s of lowercase English letters and an integer array shifts of the same length.

Call the shift() of a letter, the next letter in the alphabet, (wrapping around so that 'z' becomes 'a').


	For example, shift('a') = 'b', shift('t') = 'u', and shift('z') = 'a'.


Now for each shifts[i] = x, we want to shift the first i + 1 letters of s, x times.

Return the final string after all such shifts to s are applied.

&nbsp;
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"


&nbsp;
Constraints:


	1 &lt;= s.length &lt;= 105
	s consists of lowercase English letters.
	shifts.length == s.length
	0 &lt;= shifts[i] &lt;= 109


class Solution:
    def shiftingLetters(self, s: str, shifts: List[int]) -> str:
        n = len(s)
        nums = []
        sums = 0
        for i in shifts[::-1]:
            sums = (sums+i)%26
            nums.append(sums)
        nums = nums[::-1]
        
        res = ''
        for i, ch in enumerate(s):
            val = ord(s[i]) + nums[i]
            while val > 122:
                val -= 26
            res += chr(val)
        
        return res
class Solution {
    public String shiftingLetters(String s, int[] shifts) {
        char[] arr = s.toCharArray();
        int[] arr1 = new int[shifts.length];
        arr1[arr1.length-1] = (shifts[shifts.length-1])%26;
        for(int i =shifts.length -2 ;i>=0 ;i--){
            arr1[i] = (shifts[i] + arr1[i+1])%26;
        }
        for(int i =0; i<arr.length ; i++ ){
            int c = (int)(arr[i]);
            int n = c+arr1[i];
            if(n>122){
                    int m = arr1[i] -(122-c);
                    n = m+96;
                }
            char ch = (char)n;
            arr[i] = ch;

        }
        String string = new String(arr);
        return string;

    }
}
class Solution {
    void shift(string& s, int times, int amt)
    {
        const int clampL = 97;
        const int clampR = 123;
        
        for (int i = 0; i <= times; i++)
        {
            int op = (s[i] + amt) % clampR;
            
            if (op < clampL)
                op += clampL;
            
            s[i] = op;
        }
    }
public:
    string shiftingLetters(string s, vector<int>& shifts) {
        
        for (int i = 0; i < shifts.size(); i++)
            shift(s,i,shifts[i]);
        
        return s;
    }
};
// 848. Shifting Letters
var shiftingLetters = function(s, shifts) {
	let res = '', i = shifts.length;
	shifts.push(0);
	while (--i >= 0) {
		shifts[i] += shifts[i+1];
		res = String.fromCharCode((s.charCodeAt(i) - 97 + shifts[i]) % 26 + 97) + res;
	}
	return res;
};
Shifting Letters