Problem · String
Batch Caesar Cipher
Learn this problemProblem statement
Process a batch of Caesar-cipher operations. For index i, apply actions[i] to texts[i] using shifts[i].
encryptmoves each English letter forward through its alphabet.decryptmoves each English letter backward through its alphabet.- Movement wraps independently within
AthroughZandathroughz. - Every nonletter remains unchanged.
Return one transformed string for each operation, in input order. Reduce each shift modulo 26 before applying it.
Function
caesarCipher(actions: String[], texts: String[], shifts: int[]) → String[]Examples
Example 1
actions = ["encrypt","decrypt","encrypt"]texts = ["Abc-XYZ!","Bcd-YZA!","Hello, World!"]shifts = [1,1,13]return = ["Bcd-YZA!","Abc-XYZ!","Uryyb, Jbeyq!"]Uppercase and lowercase letters wrap within their own alphabets. Punctuation and spaces stay in place. A shift of 13 maps Hello, World! to Uryyb, Jbeyq!.
Example 2
actions = ["encrypt","decrypt"]texts = ["No change 123","Zz"]shifts = [0,52]return = ["No change 123","Zz"]Shifts of 0 and 52 are both equivalent to no movement.
Constraints
1 <= actions.length <= 10000actions.length == texts.length == shifts.length- Each action is exactly
encryptordecrypt. 0 <= texts[i].length <= 100000- The sum of all text lengths is at most
100000. 0 <= shifts[i] <= 10^9- Every text contains printable ASCII characters.