Shifting Letters II: Efficient String Shifting With Prefix Sum
We need to avoid shifting characters one by one for each shift, so we use prefix sum to efficiently apply cumulative shifts to each character in the string.
2381. Shifting Letters II Difficulty: Medium Topics: Array, String, Prefix Sum You are given a string s of lowercase English letters and a 2D integer array shifts where shifts[i] = [starti, endi, directioni]. For every i, shift the characters in s from the index starti to the index endi (inclusive) forward if directioni = 1, or shift the characters backward if directioni = 0. Shifting a character forward means replacing it with the next letter in the alphabet (wrapping around so that 'z' becomes 'a'). Similarly, shifting a character backward means replacing it with the previous letter in the a...