Camel Case Conversion
Filed under TCS · Also reported at Optum (UnitedHealth Group)
Free read 1 of 3Confirm the exact definition of 'opposite to camel case' (usually snake_case or space-separated lowercase words from camelCase).
The question
Given a sentence or string, process it in a way opposite to standard camel case conversion rules (e.g., converting a camelCase string into space-separated words with lowercase letters, or vice versa depending on exact prompt conventions).
Constraints
- 1 <= string length <= 1000
- String contains alphanumeric characters and spaces.
Examples
- Input
- "camelCaseString"
- Output
- "camel case string"
- Why
- Uppercase letters are preceded by a space and converted to lowercase.
Approach
Confirm the exact definition of 'opposite to camel case' (usually snake_case or space-separated lowercase words from camelCase).
Iterate through characters, check if uppercase, and insert spaces before them while lowercasing.
Use regular expressions to find uppercase boundaries or iterate once constructing a list of characters, joining efficiently.
Empty strings, single-character strings, or strings with no uppercase letters.
Solution
O(N) time, O(N) space
import re
def reverse_camel_case(s):
res = re.sub(r'([A-Z])', r' \1', s)
return res.lower().strip()
Tips
- What they are testing: Test with all lowercase, all uppercase, mixed camelCase, and strings with numbers.
- Common mistake: Incorrectly handling consecutive uppercase letters or missing the first character capitalization rule.
Related TCS questions
Collected from public candidate posts and coding forums. Updated Nov 2026.