Understand
30-second explanation
Build the interview-ready mental model before comparing implementations.
For each char in 'A'..'Z', add 32 to its ASCII code; leave others unchanged. Or call `toLowerCase()`.
Interview contextWhat is testedWhere candidates slipHow to stand outExplore interview contextHide interview context
What's being tested
Whether you apply the case shift in the correct direction with a guard.
Where candidates slip
Wrong sign, or shifting non-letters.
How to stand out
Mention locale-aware lowercasing for non-ASCII.
Choose
Compare the available approaches
Use constraints and trade-offs to select the route you can defend in an interview.
Learn & trace
Build each solution step by step
Move from the core idea to a visual trace, implementation, proof, and edge cases.
Approach 1 of 1 · Optimal
ASCII shift
1Hint 1Explore hintHide hint
Same 32 gap — which direction lowercases?
2Hint 2Explore hintHide hint
Add 32 to A–Z letters; guard the range.
3Hint 3Explore hintHide hint
Leave non-letters untouched.
A · Core idea
The mirror of to-uppercase: add 32 to an uppercase letter to get its lowercase form, since 'A'=65 and 'a'=97 differ by exactly 32.
Why guard A–Z. Only uppercase letters should change; the range check leaves digits, spaces, and symbols alone. Adding 32 to a non-letter would produce garbage.
Direction. Add 32 to go down to lowercase; subtracting would uppercase. Keeping the two directions straight (−32 up, +32 down) is the whole trick.
Library note. toLowerCase() handles locale and non-Latin scripts; the manual shift is the ASCII demonstration.
B · Visual dry run
Interactive dry run
Select a frame to connect the decision with its visual state.
s = "Ab1"A
in A-Z → +32
a"ab1"C · Code with teaching comments
D · Why it works and complexityO(n) timeO(n) spaceOpen the invariant and proofExplore the proofHide the proof
ComplexityO(n) time, O(n) space — one range check and possible shift per character.
E · Edge cases and pitfalls5s = "HELLO" — → "hello".Explore edge casesHide edge cases
Edge cases handled
s = "HELLO"→ "hello".s = "AbC1"Digit unchanged → "abc1".s = "z"Already lower → "z".
Pitfalls
- Subtracting 32 (uppercases) by mistake.
- Touching non-letters.
Practice
Try the solution yourself
Edit the optimal implementation, test another input, and observe the result.
Editable code previewpublic String toLower(String s) { char[] c = s.toCharArray(); for (int i = 0; i < c.length; i++) { if (c[i] >= 'A' && c[i] <= 'Z') c[i] += 32; }Explore the playgroundClose the playground
Avoid mistakes
Recognize the interview traps
Understand why common attempts fail before reviewing the corrected implementation.
- Subtracting 32 (that uppercases) by mistake.
- Touching non-letters.
Revise
Carry the pattern into the interview
Pattern to remember
ASCII case shift
Code pattern to memorize
if 'A'<=ch<='Z': ch += 32Rules to remember
- 1Lower = upper + 32.
- 2Guard with A-Z range.
- 3Leave others alone.
Use this pattern when
- ASCII case manipulation
Interview takeaway
Lowercasing is +32; uppercasing is −32.
Continue
Transfer the pattern to another problem
Use a direct variation or pattern sibling to prove the idea is reusable.
Transferable patternA core fresher pattern: ASCII case shift. Master it on small inputs and it transfers to harder problems.
Practice queueDirect variations and pattern siblings
Direct follow-ups