Given two strings, find if we can make first string from second by deleting some characters from second and rearranging remaining characters.
Input : s1 = ABHISHEKsinGH : s2 = gfhfBHkooIHnfndSHEKsiAnG Output : Possible Input : s1 = Hello : s2 = dnaKfhelddf Output : Not Possible Input : s1 = GeeksforGeeks : s2 = rteksfoGrdsskGeggehes Output : Possible
We have existing solution for this problem please refer Make a string from another by deletion and rearrangement of characters link. We will this problem quickly in python. Approach is very simple,
- Convert both string into dictionary using Counter(iterable) method, each dictionary contains characters within string as Key and their frequencies as Value.
- Now take intersection of two dictionaries and compare resultant output with dictionary of first string, if both are equal that means it is possible to convert string otherwise not.
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Make a string from another by deletion and rearrangement of characters
- Python dictionary, set and counter to check if frequencies can become same
- Dictionary and counter in Python to find winner of election
- Python | Find common elements in three sorted arrays by dictionary intersection
- Using Counter() in Python to find minimum character removal to make two strings anagram
- String slicing in Python to check if a string can become empty by recursive deletion
- Python | Case Counter in String
- Python Counter| Find all duplicate characters in string
- Python | Convert string dictionary to dictionary
- Python | Intersection of two String
- Minimum Number of Manipulations required to make two Strings Anagram Without Deletion of Character
- Python - Convert key-value String to dictionary
- Python - Convert Dictionary to Concatenated String
- Python | Converting list string to dictionary
- Python program to create a dictionary from a string
- Python - Concatenate Dictionary string values
- Python | Convert dictionary object into string
- Python | Converting String content to dictionary
- Python Dictionary to find mirror characters in a string
- Python | Convert byteString key:value pair of dictionary to String
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai