Tap here to switch tabs
Problem
Submissions

Problem: Shifting Letters II

Try to solve the Shifting Letters II problem.

Statement

You are given a string s of lowercase English letters and a 22D integer array shifts, where each element shifts[i] =[= [start_i, end_i, direction_i]].

For every operation in shifts:

  • If direction_i =1= 1, shift the characters in s from index start_i to index end_i (inclusive) forward by 11 in the alphabet, wrapping around such that 'z' becomes 'a'.

  • If direction_i =0= 0, shift the characters in s from index start_i to index end_i (inclusive) backward by 11 in the alphabet, wrapping around such that 'a' becomes 'z'.

Return the final string after all the shifts have been applied to s.

Constraints:

  • 1≤1 \leq s.length, shifts.length ≤5imes104\leq 5 imes 10^4

  • shifts[i].length =3= 3

  • 0≤0 \leq start_i ≤\leq end_i << s.length

  • 0≤0 \leq direction_i ≤1\leq 1

  • s consists of lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Shifting Letters II

Try to solve the Shifting Letters II problem.

Statement

You are given a string s of lowercase English letters and a 22D integer array shifts, where each element shifts[i] =[= [start_i, end_i, direction_i]].

For every operation in shifts:

  • If direction_i =1= 1, shift the characters in s from index start_i to index end_i (inclusive) forward by 11 in the alphabet, wrapping around such that 'z' becomes 'a'.

  • If direction_i =0= 0, shift the characters in s from index start_i to index end_i (inclusive) backward by 11 in the alphabet, wrapping around such that 'a' becomes 'z'.

Return the final string after all the shifts have been applied to s.

Constraints:

  • 1≤1 \leq s.length, shifts.length ≤5imes104\leq 5 imes 10^4

  • shifts[i].length =3= 3

  • 0≤0 \leq start_i ≤\leq end_i << s.length

  • 0≤0 \leq direction_i ≤1\leq 1

  • s consists of lowercase English letters.