Shifting Letters II
You are given a string s of lowercase English letters and a 2D array shifts where shifts[i] = [start, end, direction]. For each shift, if direction == 1 shift every character in s from index start to end (inclusive) forward one letter (wrapping 'z' to 'a'); if direction == 0 shift them backward one letter (wrapping 'a' to 'z'). Return the final string after applying all shifts.
Open official problem prompt ↗Determine the net letter offset applied to each character after many overlapping forward/backward range shifts, then rebuild the final string efficiently.
Like a row of dials on a combination lock: each instruction nudges a contiguous block of dials up or down. Rather than turning every dial for every instruction, you tally the net turns per dial and spin each one just once at the end.
- Input
- s = "abc", shifts = [[0,1,0],[1,2,1],[0,2,1]]
- Output
- "ace"
- Why
- Net shifts are [0, +1, +2]: 'a' stays 'a', 'b'->'c', 'c'->'e', giving "ace".
1 <= s.length, shifts.length <= 5 * 10^4shifts[i].length == 30 <= start_i <= end_i < s.length0 <= direction_i <= 1s consists of lowercase English letters