Replace Spaces
You have been given a string 'STR' of words. You need to replace all the spaces between words with “@40”.
Input Format:
The first line contains a single integer ‘T’ representing the number of test cases.
The first line of each test case will contain a single string 'STR' consisting of one or more words.
Output Format:
For each test case, return the modified string after replacing all the spaces between words with “@40”.
Print the output of each test case in a separate line.
Note:
You don’t need to print anything, It has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 50
0 <= |STR| <= 100
Where ‘|STR|’ is the length of a particular string including spaces.
Time limit: 1 sec
CodingNinjas
author
2y
One approach could be to calculate the number of spaces in the given string. Calculate the new length of the string as original length + 2*(number of spaces). Create a new string of the length calcula...read more
CodingNinjas
author
2y
Using Another String
The basic idea is to use a separate string to store the resultant string. Copy characters from the original string to the resultant string one by one, and whenever there comes a sp...read more
CodingNinjas
author
2y
In-place manipulation
The basic idea of this approach is to assume that string have extra space in the input string.
For example:
S: “Coding Ninjas “
Extra space, in the end, can be used to add @40 in t...read more
Add answer anonymously...
Top Housing.com Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Housing.com Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app