Smallest number possible by swapping adjacent even odd pairs | Function to return the smallest number possible ; Arrays to store odd and even digits in the order of their appearance in the given string ; Insert the odd and even digits ; pointer to odd digit ; pointer to even digit ; In case number of even and odd digits are not equal If odd digits are remaining ; If even digits are remaining ; Removal of leading 0 's  ; Driver Code
def findAns ( s ) : NEW_LINE INDENT odd = [ ] NEW_LINE even = [ ] NEW_LINE for c in s : NEW_LINE INDENT digit = int ( c ) NEW_LINE if ( digit & 1 ) : NEW_LINE INDENT odd . append ( digit ) NEW_LINE DEDENT else : NEW_LINE INDENT even . append ( digit ) NEW_LINE DEDENT DEDENT i = 0 NEW_LINE j = 0 NEW_LINE ans = " " NEW_LINE while ( i < len ( odd ) and j < len ( even ) ) : NEW_LINE INDENT if ( odd [ i ] < even [ j ] ) : NEW_LINE INDENT ans += str ( odd [ i ] ) NEW_LINE i = i + 1 NEW_LINE DEDENT else : NEW_LINE INDENT ans += str ( even [ j ] ) NEW_LINE j = j + 1 NEW_LINE DEDENT DEDENT while ( i < len ( odd ) ) : NEW_LINE INDENT ans += str ( odd [ i ] ) NEW_LINE i = i + 1 NEW_LINE DEDENT while ( j < len ( even ) ) : NEW_LINE INDENT ans += str ( even [ j ] ) NEW_LINE j = j + 1 NEW_LINE DEDENT while ( ans [ 0 ] == '0' ) : NEW_LINE INDENT ans = ans [ 1 : ] NEW_LINE DEDENT return ans NEW_LINE DEDENT s = "894687536" NEW_LINE print ( findAns ( s ) ) NEW_LINE