26. Shifting Letters
We have a string S
of lowercase letters, and an integer array shifts
.
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.
Example 1:
Approach
Brute Force: Iterate through shift and shift the characters. It gives TLE Optimized: Suffix Sum Pre compute the total number of shifts required
Solution: (Suffix Sum)
Time Complexity: O(n)
Last updated