Lexicographically smallest string formed repeatedly deleting character from substring 10 | Function to find smallest lexicogra - phically smallest string ; Stores the index of last occuring 0 ; Stores the lexicographically smallest string ; Traverse the string S ; If str [ i ] is 0 ; Assign i to lastZe ; Traverse the string str ; If i is less than or equal to lastZe and str [ i ] is 0 ; If i is greater than lastZe ; Return ans ; Input ; Function Call
function lexicographicallySmallestString ( S , N ) { var LastZe = - 1 ; var ans = " " ; for ( var i = N - 1 ; i >= 0 ; i -- ) { if ( S . charAt ( i ) == ' ' ) { LastZe = i ; break ; } } for ( var i = 0 ; i < N ; i ++ ) { if ( i <= LastZe && S . charAt ( i ) == ' ' ) ans += S . charAt ( i ) ; else if ( i > LastZe ) ans += S . charAt ( i ) ; } return ans ; } var S = " " ; var N = S . length ; document . write ( lexicographicallySmallestString ( S , N ) ) ;