Tutorialspoint
Problem
Solution
Submissions

Convert a String into a Camel Case Format

Certification: Intermediate Level Accuracy: 83.33% Submissions: 18 Points: 5

Write a Python function to convert a given string into camel case format.

Example 1
  • Input: s = "hello_world"
  • Output: "helloWorld"
  • Explanation:
    • Step 1: Split the string "hello_world" by underscore character, resulting in ["hello", "world"].
    • Step 2: Keep the first word "hello" as is (lowercase).
    • Step 3: Capitalize the first letter of the remaining words: "world" becomes "World".
    • Step 4: Join all words together: "hello" + "World" = "helloWorld".
    • Step 5: Return the camel case string "helloWorld".
Example 2
  • Input: s = "this_is_a_test"
  • Output: "thisIsATest"
  • Explanation:
    • Step 1: Split the string "this_is_a_test" by underscore character, resulting in ["this", "is", "a", "test"].
    • Step 2: Keep the first word "this" as is (lowercase).
    • Step 3: Capitalize the first letter of the remaining words: "is" becomes "Is", "a" becomes "A", "test" becomes "Test".
    • Step 4: Join all words together: "this" + "Is" + "A" + "Test" = "thisIsATest".
    • Step 5: Return the camel case string "thisIsATest".
Constraints
  • 1 <= len(string) <= 1000
  • Time Complexity: O(n) where n is the length of the string
  • Space Complexity: O(n)
StringsFunctions / MethodsDeloitteSnowflake
Editorial

Login to view the detailed solution and explanation for this problem.

My Submissions
All Solutions
Lang Status Date Code
You do not have any submissions for this problem.
User Lang Status Date Code
No submissions found.

Please Login to continue
Solve Problems

 
 
 
Output Window

Don't have an account? Register

Solution Hints

  • Split the string by underscores.
  • Capitalize the first letter of each word except the first word.
  • Join the words together without spaces.

Steps to solve by this approach:

 Step 1: Split the input string by underscores to create a list of words
 
 Step 2: Take the first word as-is (lowercase) for the start of the camelCase string  
 Step 3: Iterate through the remaining words (from index 1 onwards)  
 Step 4: For each word, capitalize its first letter and append to the result  
 Step 5: Join all the transformed words to form the final camelCase string  
 Step 6: Return the camelCase result  
 Step 7: Example transformation: "hello_world" becomes "helloWorld"

Submitted Code :