Check if characters of a string can be made non | C ++ 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; int nonDecreasing ( string 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 ; } int main ( ) { string S = " abb ? xy ? " ; if ( nonDecreasing ( S ) ) cout << " Yes " << endl ; else cout << " No " << endl ; return 0 ; }