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 of above implementation is O(n) where n is number of characters in input string.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
- Remove spaces from a given string
- Remove extra spaces from a string
- How to remove all white spaces from a String in Java?
- Program to remove vowels from a String
- String containing first letter of every word in a given string with spaces
- URLify a given string (Replace spaces is %20)
- Removing spaces from a string using Stringstream
- Move spaces to front of string in single traversal
- Python code to move spaces to front of string in single traversal
- Remove characters from the first string which are present in the second string
- Remove "b" and "ac" from a given string
- Remove duplicates from a given string
- Remove all consecutive duplicates from the string
- Remove all occurrences of a character in a string
- Remove all characters other than alphabets from string