![]() |
VOOZH | about |
Given two strings, find if we can make first string from second by deleting some characters from second and rearranging remaining characters.
Examples:
Input : s1 = ABHISHEKsinGH, s2 = gfhfBHkooIHnfndSHEKsiAnG
Output : PossibleInput : s1 = Hello, s2 = dnaKfhelddf
Output : Not PossibleInput : s1 = GeeksforGeeks, s2 = rteksfoGrdsskGeggehes
Output : Possible
We basically need to find if one string contains characters which are subset of characters in second string. First we count occurrences of all characters in second string. Then we traverse through first string and reduce count of every character that is present in first. If at any moment, count becomes less than 0, we return false. If all counts remain greater than or equal to 0, we return true.
Implementation:
Possible
Time complexity is: O(n)
Auxiliary Space: O(256)