Check if characters of a string can be made non | Function to check if it 's possible to make the String s non decreasing ; Stores length of String ; Stores the last character that is not ' ? ' ; Traverse the String S ; If current character of the String is ' ? ' ; If s [ i ] is not ' ? ' and is less than C ; Otherwise ; Update C ; Return 1 ; Driver Code
function nonDecreasing ( s ) { let size = s . length ; var c = ' ' ; for ( let i = 0 ; i < size ; i ++ ) { if ( s [ i ] == ' ' ) { continue ; } else if ( ( s [ i ] != ' ' ) && ( s [ i ] < c ) ) { return 0 ; } else { c = s [ i ] ; } } return 1 ; } let S = " " ; if ( nonDecreasing ( S . split ( ' ' ) ) ) document . write ( " " + " " ) ; else document . write ( " " + " " ) ;