Transform a string such that it has abcd . . z as a subsequence | Java 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
import java . io . * ; public class GFG { static boolean transformString ( StringBuilder s ) { char ch = ' a ' ; if ( s . length ( ) < 26 ) return false ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( ( int ) ch > ( int ) ' z ' ) break ; if ( s . charAt ( i ) <= ch ) { s . setCharAt ( i , ch ) ; ch = ( char ) ( ( int ) ch + 1 ) ; } } if ( ch <= ' z ' ) return false ; return true ; } public static void main ( String args [ ] ) { StringBuilder str = new StringBuilder ( " aaaaaaaaaaaaaaaaaaaaaaaaaa " ) ; if ( transformString ( str ) ) System . out . println ( str . toString ( ) ) ; else System . out . println ( " Not ▁ Possible " ) ; } }