Alphabet Wheel Cipher Decrypt
viaLeetCode
Problem A cipher uses a wheel of uppercase A–Z. Decrypt an encrypted string by replacing each character with the character k positions counter-clockwise on the wheel (Z is 1 counter-clockwise from A).
Input / Output
- Input: string s of A–Z, int k.
- Output: decrypted string.
Constraints
- |s|, k up to 10^5 — reduce k mod 26 once; per-character work O(1).
Example
- s = "VTAOG", k = 2 → "TRYME" (V→T, T→R, A→Y, O→M, G→E).
Expected approach
- Caesar shift with wrap-around: out[i] = 'A' + ((s[i] − 'A' − k) mod 26 + 26) mod 26. The +26 guard handles negative modulo in most languages. O(n) time, O(1) space. Discussion: encrypt vs decrypt symmetry (shift +k vs −k) and why k mod 26 suffices.
asked …