Toggle Character Case
You are given a string s containing printable ASCII characters. Return a new string in which every lowercase English letter (a through z) becomes uppercase…
You are given a string `s` containing printable ASCII characters. Return a new string in which every lowercase English letter (`a` through `z`) becomes uppercase and every uppercase English letter (`A` through `Z`) becomes lowercase. Preserve digits, spaces, punctuation, and every other non-letter character exactly as they appear. Character order must not change.
- `0 <= s.length <= 10^5` - `s` contains printable ASCII characters (character codes 32 through 126). - Only the 52 ASCII English letters change case. - Digits, spaces, punctuation, and symbols remain unchanged and in the same positions. - The interactive visualizer accepts `0 <= s.length <= 40`; longer valid judge inputs are execution-only.
Example 1: input s = "Hello World"; output "hELLO wORLD". Every uppercase letter becomes lowercase and every lowercase letter becomes uppercase; the space is preserved.
Example 2: input s = "DSA 101!"; output "dsa 101!". The letters change case while the space, digits, and exclamation mark stay unchanged.
Example 3: input s = "aBcDe"; output "AbCdE". Each letter is toggled independently, so alternating input case becomes the opposite alternating case.
Category: Strings. Topic: strings. Difficulty: Easy. Patterns: string-processing.