![]() |
VOOZH | about |
Given a sentence having lowercase characters, the task is to convert it to Camel Case. In Camel Case, words are joined without spaces, the first word keeps its original case, and each subsequent word starts with an uppercase letter.
Examples:
Input: "i got intern at geeksforgeeks"
Output: "iGotInternAtGeeksforgeeks"Input: "here comes the garden"
Output: "hereComesTheGarden"
Approach:
The idea is to traverse the sentence and each time a space is encountered, remove it and capitalize the next character. We use a flag, capitalizeNext, to track when to capitalize the next character. When a space is encountered, we skip it and set capitalizeNext to true. Once a character is found, we capitalize it and set capitalizeNext back to false.
iGotInternAtGeeksforgeeks
Time Complexity: O(n), where n is the length of input sentence.
Auxiliary Space: O(n), to store the final result.