2381. Shifting Letters II Medium
1/**
2 * [2381] Shifting Letters II
3 *
4 * 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.
5 * 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 alphabet (wrapping around so that 'a' becomes 'z').
6 * Return the final string after all such shifts to s are applied.
7 *
8 * Example 1:
9 *
10 * Input: s = "abc", shifts = [[0,1,0],[1,2,1],[0,2,1]]
11 * Output: "ace"
12 * Explanation: Firstly, shift the characters from index 0 to index 1 backward. Now s = "zac".
13 * Secondly, shift the characters from index 1 to index 2 forward. Now s = "zbd".
14 * Finally, shift the characters from index 0 to index 2 forward. Now s = "ace".
15 * Example 2:
16 *
17 * Input: s = "dztz", shifts = [[0,0,0],[1,1,1]]
18 * Output: "catz"
19 * Explanation: Firstly, shift the characters from index 0 to index 0 backward. Now s = "cztz".
20 * Finally, shift the characters from index 1 to index 1 forward. Now s = "catz".
21 *
22 *
23 * Constraints:
24 *
25 * 1 <= s.length, shifts.length <= 5 * 10^4
26 * shifts[i].length == 3
27 * 0 <= starti <= endi < s.length
28 * 0 <= directioni <= 1
29 * s consists of lowercase English letters.
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/shifting-letters-ii/
35// discuss: https://leetcode.com/problems/shifting-letters-ii/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn shifting_letters(s: String, shifts: Vec<Vec<i32>>) -> String {
41 String::new()
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_2381() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.