Move the Spaces to Front of the String
Problem: Given a string that has set of words and spaces, write a program to move the spaces to front of string, you need to traverse the array only once and need to adjust the string in place.
string = “move these spaces to beginning”
output =” movethesepacestobeginning”
Solution:
Maintain two indices i and j. Traverse from end to beginning.
If the current index contains char, swap chars in index i with index j.
[Read More]