Given a sentence, task is to remove spaces from the sentence and rewrite in Camel case. It is a style of writing where we don’t have spaces and all words begin with capital letters. Examples:
Input : I got intern at geeksforgeeks
Output : IGotInternAtGeeksforgeeks
Input : Here comes the garden
Output : HereComesTheGarden
Simple solution: First method is to traverse sentence and one by one remove spaces by moving subsequent characters one position back and changing case of first character to capital. It takes O(n*n) time. Efficient solution : We traverse given string, while traversing we copy non space character to result and whenever we encounter space, we ignore it and change next letter to capital. Below is code implementation
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
This article is contributed by Himanshu Ranjan. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.