To Lower Case - Problem

Given a string s, your task is to transform all uppercase letters to lowercase while keeping all other characters unchanged.

This is a fundamental string manipulation problem that tests your understanding of character processing and ASCII values. You need to iterate through each character in the string and convert any uppercase letter (A-Z) to its corresponding lowercase letter (a-z).

Goal: Return a new string with all uppercase letters converted to lowercase.

Example: "Hello World!" becomes "hello world!"

Input & Output

example_1.py โ€” Basic Mixed Case
$ Input: s = "Hello"
โ€บ Output: "hello"
๐Ÿ’ก Note: The uppercase letters 'H' is converted to 'h', while lowercase letters remain unchanged
example_2.py โ€” Mixed with Numbers and Symbols
$ Input: s = "Hello123World!"
โ€บ Output: "hello123world!"
๐Ÿ’ก Note: Only uppercase letters 'H' and 'W' are converted to lowercase. Numbers and special characters remain the same
example_3.py โ€” Already Lowercase
$ Input: s = "lovely"
โ€บ Output: "lovely"
๐Ÿ’ก Note: Since all characters are already lowercase or non-alphabetic, the string remains unchanged

Constraints

  • 1 โ‰ค s.length โ‰ค 100
  • s consists only of printable ASCII characters

Visualization

Tap to expand
String Case Conversion VisualizationInput String:HeLLOProcessing:For each character:If uppercase (A-Z) โ†’ convert to lowercaseOtherwise โ†’ keep unchangedTransformOutput String:helloLegend:Uppercase (needs conversion)Lowercase (final result)Time: O(n) | Space: O(n) where n = string length
Understanding the Visualization
1
Read Character
Examine each character in the input string from left to right
2
Check Case
Determine if the character is an uppercase letter (A-Z)
3
Transform
Convert uppercase letters to lowercase, keep all other characters unchanged
4
Build Result
Append the processed character to the result string
Key Takeaway
๐ŸŽฏ Key Insight: This problem teaches fundamental string manipulation - processing each character exactly once while applying a simple transformation rule. The beauty lies in its simplicity and the fact that it has a linear time solution.
Asked in
Amazon 15 Google 12 Microsoft 8 Apple 5
23.4K Views
Low Frequency
~5 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen