Ninja wants to print a book of stories. He created a doc file and sent it to his editor to make some edits. But the file got corrupted due to some reasons and made changes in the original file. Ninja did not have a duplicate file of the same, so he wants to correct the same file. He found that the file has been changed in such a way that all the spaces have been removed from the file and the first letter after each space that used to be has been changed to the equivalent uppercase characters.
Example:If the corrupted file looks like “CodingNinjasIsACodingPlatform”, then the original file was: “coding ninjas is a coding platform”.
Ninja needs to change the corrupted file to the original file.
Note:You need to convert all the uppercase characters to lowercase characters, and you need to add a single space between every two words.
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case will contain a string ‘S’, which denotes the corrupted string that you need to to change.
Output Format:
For each test case, print a single line containing a string denoting the original sentence.
The output for every test case will be printed in a separate line.
Note:
You don't need to print anything, It has already been taken care of. Just implement the given function.
1 <= T <= 50
0 <= size of S <= 10000
where ‘T’ is the number of test cases.
where 'S’ is the corrupted string that you need to to change.
Time limit: 1 sec
2
CodingNinjasIsACodingPlatform
Hello
coding ninjas is a coding platform
hello
In the first test case,
After replacing the uppercase characters with a space followed by the lowercase conversion of the character we get:
coding ninjas is a coding platform
In the second test case,
After replacing the uppercase characters with a space followed by the lowercase conversion of the character we get:
hello
3
HelloWorld
ILoveCoding
YouCanPracticeCodingOnCodezen
hello world
i love coding
you can practice coding on codezen
Can you think of checking each character?
The basic approach is to traverse through the complete string of characters and check if the character is in uppercase or lowercase. If it is in uppercase, simply update the character with a space followed by the lowercase conversion of the character.
Algorithm:
O(N), where ‘N’ is the size of the string.
We need to traverse through the complete string only once. So, the time complexity is O(N).
O(1).
No extra space is required. So, space complexity is O(1).