Make a string from another by deletion and rearrangement of characters | CPP 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int MAX_CHAR = 256 ; bool isPossible ( string & s1 , string & s2 ) { int count [ MAX_CHAR ] = { 0 } ; for ( int i = 0 ; i < s2 . length ( ) ; i ++ ) count [ s2 [ i ] ] ++ ; for ( int i = 0 ; i < s1 . length ( ) ; i ++ ) { if ( count [ s1 [ i ] ] == 0 ) return false ; count [ s1 [ i ] ] -- ; } return true ; } int main ( ) { string s1 = " GeeksforGeeks " , s2 = " rteksfoGrdsskGeggehes " ; if ( isPossible ( s1 , s2 ) ) cout << " Possible " ; else cout << " Not ▁ Possible STRNEWLINE " ; return 0 ; }