the +32 shift
In ASCII, 'A' is 65 and 'a' is 97. The gap is exactly 32 for every letter pair. Adding 32 to any uppercase letter produces its lowercase partner — no lookup table needed.
A search engine normalizes user queries before matching — converting "WiFi Router"
to "wifi router" ensures case-insensitive lookups without a translation table. In
ASCII, every uppercase letter sits exactly 32 positions before its lowercase partner.
One pass checks each character's code: if it falls between 65 and 90, add 32;
otherwise leave it alone. O(n) time. O(n) space.
The conversion relies on a fixed numeric relationship between uppercase and lowercase letters in the ASCII table.
In ASCII, 'A' is 65 and 'a' is 97. The gap is exactly 32 for every letter pair. Adding 32 to any uppercase letter produces its lowercase partner — no lookup table needed.
Only characters with ASCII codes between 65 ('A') and 90 ('Z') should be shifted. Digits, punctuation, spaces, and already-lowercase letters must pass through unchanged.
Each character is examined exactly once. The convert-or-keep decision depends only on whether the character falls in the uppercase range — no state carried between iterations.
A single loop with one range check and one arithmetic operation.
Create a character array of the same length as the input string.
For each character, test whether its code is between 65 ('A') and 90 ('Z') inclusive.
If uppercase, add 32 to produce the lowercase character. Otherwise copy the character unchanged.
After all characters are processed, join and return the result string.
Some inputs pass through the loop without a single conversion.
Every character's ASCII code is already above 90. The range check fails for all positions — the output is identical to the input.
Non-letter characters have codes outside [65, 90]. Without the range
guard, adding 32 to '1' (49) would produce 'Q' (81) —
a silent corruption.
'A' (65) and 'Z' (90) sit at the edges of the
range. Both convert correctly: 65 + 32 = 97 ('a'),
90 + 32 = 122 ('z').