C++ Program to remove spaces from a string
Given a string, remove all spaces from it. For example “g e e k” should be converted to “geek” and ” g e ” should be converted to “ge”. The idea is to traverse the string from left to right and ignore spaces while traversing. We need to keep track of two indexes, one for current character being red and other for current index in output.
Time complexity: O(n) where n is number of characters in input string.
Axuiliary Space: O(1)
Approach 2: using in-built function
Main idea in this approach is we will traverse the whole string and will delete the space by using in-built erase function from C++ STL.
Time complexity will be O(N) where N is length of string and the solution will also be in-place solution.
origional string is: Gee k final updated string: Geek origional string is: G e e k final updated string: Geek