


Given a string âSTRâ, you need to remove spaces from the string âSTRâ and rewrite in the Pascal case. Your task is to return the string âSTRâ.
In the Pascal case writing style we donât have spaces between words and all words begin with uppercase letters including the first word.
Note:
Input string âSTRâ will only consist of lowercase English Alphabets. The string will not contain white space at the beginning and end of the string.
The first line of input contains an integer âTâ denoting the number of test cases to run. Then the test case follows.
The first and the only line of each test case contains the string 'STR'.
Output Format :
For each test case, return a string that is written in the Pascal case style.
Output for each test case will be printed in a new line.
Note:
You do not need to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= |STR| <= 10^5
Where |STR| denotes the length of âSTRâ
Time Limit: 1sec
2
coding ninja is great
i am pascal case
CodingNinjaIsGreat
IAmPascalCase
In the first case,
We have four words âcodingâ, âninja, âisâ, âgreatâ. After we remove the space between these words and change the first letter of each word to an uppercase letter. the resulting string will be âCodingNinjaIsGreatâ in the pascal case.
In the second case,
We have four words âiâ, âamâ, âpascalâ, âcaseâ. After we remove the space between these words and change the first letter of each word to an uppercase letter. the resulting string will be âIAmPascalCaseâ in the pascal case.
2
aba cbs llb
a b c d
AbaCbsLlb
ABCD
How can you find the first letter of each word?
We can iterate over the string âSTRâ and maintain the resultant string in âanswerâ. On each character check if that character is white space (â â) then change the next character to uppercase and do not include white space in the string âanswerâ, else append that character in the string âanswerâ.
Algorithm:
O(N), where âNâ denotes the length of STR.
Since we iterate through the string âSTRâ only once, the time complexity is O(N).
O(N), where âNâ denotes the length of STR.
Since we store at most âNâ characters in the string âanswerâ, the space complexity is O(N).