Loading...
You are given a string s of lowercase English letters and a 2D integer array operations, where each operations[i] = [start, end, direction] describes a shift applied to every character of s at an index in the inclusive range [start, end].
direction == 1, each affected character is shifted forward by one: it is replaced with the next letter in the alphabet, wrapping so that 'z' becomes 'a'.direction == 0, each affected character is shifted backward by one: it is replaced with the previous letter in the alphabet, wrapping so that 'a' becomes 'z'.Apply the operations in order. Return the final string after all shifts have been applied. Note that forward and backward shifts on a character are cumulative and commutative, so only the net number of shifts at each index matters.
Input: s = "abc", operations = [[0,1,0],[1,2,1],[0,2,1]]
Output: "ace"
Explanation:
Shift indices 0..1 backward: "abc" -> "zac".
Shift indices 1..2 forward: "zac" -> "zbd".
Shift indices 0..2 forward: "zbd" -> "ace".
Input: s = "dztz", operations = [[0,0,0],[1,1,1]]
Output: "catz"
Explanation:
Shift index 0 backward: "dztz" -> "cztz".
Shift index 1 forward: "cztz" -> "catz".
s.length, operations.length ≤5×104operations[i].length ==3start ≤ end < s.lengthdirection ≤1s consists of lowercase English letters.Click "Run" to test with sample cases or "Submit" to run all tests.