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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Remove spaces from a given string
- Remove extra spaces from a string
- How to remove all white spaces from a String in Java?
- C program to trim leading white spaces from String
- Program to remove vowels from a String
- Program to remove HTML tags from a given 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 comments from a given C/C++ program
- Remove duplicates from a given string
- Remove the first and last occurrence of a given Character from a String
- Remove odd frequency characters from the string
- Remove all consecutive duplicates from the string
- Remove all duplicates from a given string in Python
- Remove consecutive vowels from string