205. Shift the Letters

EasyStringString

You are given a string s and an array shifts of the same length.

Call the shift of a letter the next letter in the alphabet (wrapping 'z' → 'a').

For each i in [0..n-1], the i-th shift operation shifts each of s[i..n-1] by one.
So after all operations, s[i] is shifted by sum(shifts[i..n-1]) positions.

Return the final string.

Input format: s|shift0|shift1|...|shiftn-1

Input: String s followed by shifts separated by '|'.

Output: The resulting string after all shifts.

Examples

Example 1
Input: abc|3|5|9
Output: rpl
Explanation: Suffix sums: [17,14,9]. a+17=r, b+14=p, c+9=l → 'rpl'.
Example 2
Input: aaa|1|2|3
Output: gfd
Explanation: Suffix sums: [6,5,3]. a+6=g, a+5=f, a+3=d → 'gfd'.
Example 3
Input: xyz|3|5|9
Output: oli
Explanation: Suffix sums: [17,14,9]; with wrapping.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →