Check if characters of a string can be made non | Java program for the above approach ; 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
import java . util . * ; class GFG { static int nonDecreasing ( char [ ] s ) { int size = s . length ; char c = ' a ' ; for ( int i = 0 ; i < size ; i ++ ) { if ( s [ i ] == ' ? ' ) { continue ; } else if ( ( s [ i ] != ' ? ' ) && ( s [ i ] < c ) ) { return 0 ; } else { c = s [ i ] ; } } return 1 ; } public static void main ( String [ ] args ) { String S = " abb ? xy ? " ; if ( nonDecreasing ( S . toCharArray ( ) ) == 1 ) System . out . print ( " Yes " + "NEW_LINE"); else System . out . print ( " No " + "NEW_LINE"); } }