Make a string from another by deletion and rearrangement of characters | Java program to find if it is possible to make a string from characters present in other string . ; Returns true if it is possible to make s1 from characters present in s2 . ; Count occurrences of all characters present in s2 . . ; For every character , present in s1 , reduce its count if count is more than 0. ; Driver code
class StringfromCharacters { static final int MAX_CHAR = 256 ; static boolean isPossible ( String s1 , String s2 ) { int count [ ] = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < s2 . length ( ) ; i ++ ) count [ ( int ) s2 . charAt ( i ) ] ++ ; for ( int i = 0 ; i < s1 . length ( ) ; i ++ ) { if ( count [ ( int ) s1 . charAt ( i ) ] == 0 ) return false ; count [ ( int ) s1 . charAt ( i ) ] -- ; } return true ; } public static void main ( String args [ ] ) { String s1 = " GeeksforGeeks " , s2 = " rteksfoGrdsskGeggehes " ; if ( isPossible ( s1 , s2 ) ) System . out . println ( " Possible " ) ; else System . out . println ( " Not ▁ Possible " ) ; } }