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:
- Count occurrences of a word in string
- Count of occurrences of a "1(0+)1" pattern in a string
- Count occurrences of a sub-string with one variable character
- Count occurrences of a character in a repeated string
- Find the count of palindromic sub-string of a string in its sorted form
- Replace all occurrences of pi with 3.14 in a given string
- Replace all occurrences of a string with space
- Remove all occurrences of a character in a string
- Replace all occurrences of string AB with C without using extra space
- Rearrange a binary string as alternate x and y occurrences
- 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 subsequences in first string which are anagrams of the second string
- Swap all occurrences of two characters to get lexicographically smallest string
- Number of permutations of a string in which all the occurrences of a given character occurs together
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.