Transform a string such that it has abcd . . z as a subsequence | C Plus Plus Program to transform the given string to contain the required subsequence ; function to transform string with string passed as reference ; initializing the variable ch to ' a ' ; if the length of string is less than 26 , we can 't obtain the required  subsequence ; if ch has reached ' z ' , it means we have transformed our string such that required subsequence can be obtained ; current character is not greater than ch , then replace it with ch and increment ch ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool transformString ( string & s ) { char ch = ' a ' ; if ( s . size ( ) < 26 ) return false ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) { if ( int ( ch ) > int ( ' z ' ) ) break ; if ( s [ i ] <= ch ) { s [ i ] = ch ; ch = char ( int ( ch ) + 1 ) ; } } if ( ch <= ' z ' ) return false ; return true ; } int main ( ) { string str = " aaaaaaaaaaaaaaaaaaaaaaaaaa " ; if ( transformString ( str ) ) cout << str << endl ; else cout << " Not ▁ Possible " << endl ; return 0 ; }