Make a string from another by deletion and rearrangement of characters | Python 3 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
MAX_CHAR = 256 NEW_LINE def isPossible ( s1 , s2 ) : NEW_LINE INDENT count = [ 0 ] * MAX_CHAR NEW_LINE for i in range ( len ( s2 ) ) : NEW_LINE INDENT count [ ord ( s2 [ i ] ) ] += 1 NEW_LINE DEDENT for i in range ( len ( s1 ) ) : NEW_LINE INDENT if ( count [ ord ( s1 [ i ] ) ] == 0 ) : NEW_LINE INDENT return False NEW_LINE DEDENT count [ ord ( s1 [ i ] ) ] -= 1 NEW_LINE DEDENT return True NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s1 = " GeeksforGeeks " NEW_LINE s2 = " rteksfoGrdsskGeggehes " NEW_LINE if ( isPossible ( s1 , s2 ) ) : NEW_LINE INDENT print ( " Possible " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " Not ▁ Possible " ) NEW_LINE DEDENT DEDENT