To Lower Case · Optimal Solution

Add 32 to every uppercase letter.

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.


Interactive

Watch each character convert in place


Concept

ASCII arithmetic, one rule

The conversion relies on a fixed numeric relationship between uppercase and lowercase letters in the ASCII table.

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.

range guard

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.

one pass, one decision

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.


Algorithm

Check, shift, or keep

A single loop with one range check and one arithmetic operation.

  1. 1

    Allocate the result

    Create a character array of the same length as the input string.

  2. 2

    Check the ASCII range

    For each character, test whether its code is between 65 ('A') and 90 ('Z') inclusive.

  3. 3

    Convert or keep

    If uppercase, add 32 to produce the lowercase character. Otherwise copy the character unchanged.

  4. 4

    Return the result

    After all characters are processed, join and return the result string.


Edge Cases

Where nothing changes

Some inputs pass through the loop without a single conversion.

All lowercase

Every character's ASCII code is already above 90. The range check fails for all positions — the output is identical to the input.

Digits and punctuation

Non-letter characters have codes outside [65, 90]. Without the range guard, adding 32 to '1' (49) would produce 'Q' (81) — a silent corruption.

Boundary letters A and Z

'A' (65) and 'Z' (90) sit at the edges of the range. Both convert correctly: 65 + 32 = 97 ('a'), 90 + 32 = 122 ('z').