Arrays and Hashing Difference arrays
595. Shifting Letters II
You are given a string s of lowercase English letters and a list shifts. Each shift is a triple
[start, end, direction]. It moves every letter of s from index start to index end, both ends included,
one step through the alphabet: forward when direction is 1, and backward when direction is 0.
The alphabet wraps around. A forward step turns z into a, and a backward step turns a into z.
Apply every shift and return the final string. Answers are shown in double quotes.
Example 1
Input: s = "away"
shifts = [[1, 3, 1], [0, 1, 0], [2, 3, 1]]
"zwca"Explanation: Index 0 gets one backward step, so a wraps to z. Index 1 gets one step each way, so w stays. Indexes
2 and 3 get two forward steps each: a becomes c, and y passes z and wraps to a.
Example 2
Input: s = "b", shifts = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]
"y"Explanation: Three backward steps take b to a, then to z, then to y.
Example 3
Input: s = "dog"
shifts = [[0, 2, 1], [0, 1, 0], [2, 2, 0]]
"dog"Explanation: Every letter gets one forward step and one backward step, so the string comes back unchanged.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ s.length ≤ 105sholds only lowercase English letters.1 ≤ shifts.length ≤ 105shifts[i] = [start, end, direction]0 ≤ start ≤ end < s.lengthdirectionis 0 or 1.
Clarifying questions
What you would ask an interviewer before writing any code.