Move spaces to front of string in single traversal | Function to find spaces and move to beginning ; Traverse from end and swap spaces ; Driver code
def moveSpaceInFront ( s ) : NEW_LINE INDENT i = len ( s ) - 1 ; NEW_LINE for j in range ( i , - 1 , - 1 ) : NEW_LINE INDENT if ( s [ j ] != ' ▁ ' ) : NEW_LINE INDENT s = swap ( s , i , j ) ; NEW_LINE i -= 1 ; NEW_LINE DEDENT DEDENT return s ; NEW_LINE DEDENT def swap ( c , i , j ) : NEW_LINE INDENT c = list ( c ) NEW_LINE c [ i ] , c [ j ] = c [ j ] , c [ i ] NEW_LINE return ' ' . join ( c ) NEW_LINE DEDENT s = " Hey ▁ there , ▁ it ' s ▁ GeeksforGeeks " ; NEW_LINE s = moveSpaceInFront ( s ) ; NEW_LINE print ( s ) ; NEW_LINE