Given two strings str1 and str2 where str1 being the parent string. The task is to find out the number of string as str2 that can be constructed using letters of str1.
Note: All the letters are in lowercase and each character should be used only once.
Input: str1 = "geeksforgeeks", str2 = "geeks" Output: 2 Input: str1 = "geekgoinggeeky", str2 = "geeks" Output: 0
Approach: Store the frequency of characters of str2 in hash2, and do the same for str1 in hash1. Now, find out the minimum value of hash1[i]/hash2[i] for all i where hash2[i]>0.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count of occurrences of a "1(0+)1" pattern in a string
- Count occurrences of a word in string
- Count occurrences of a character in a repeated string
- Count occurrences of a sub-string with one variable character
- Count of occurrences of each prefix in a string using modified KMP algorithm
- Replace all occurrences of pi with 3.14 in a given string
- Remove all occurrences of a character in a string
- Replace all occurrences of a string with space
- Find the count of palindromic sub-string of a string in its sorted form
- Rearrange a binary string as alternate x and y occurrences
- Replace all occurrences of string AB with C without using extra space
- Check if a binary string has two consecutive occurrences of one everywhere
- Recursive program to replace all occurrences of pi with 3.14 in a given string
- Count of times second string can be formed from the characters of first string
- Number of permutations of a string in which all the occurrences of a given character occurs together
- Remove all occurrences of a character in a string | Recursive approach
- Remove duplicates from string keeping the order according to last occurrences
- Print the string by ignoring alternate occurrences of any character
- Swap all occurrences of two characters to get lexicographically smallest string
- Count subsequences in first string which are anagrams of the second 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.