Given two strings str and patt, the task is to find the count of times patt can be formed using the characters of str.
Input: str = “geeksforgeeks”, patt = “geeks”
“geeks” can be made at most twice from
the characters of “geeksforgeeks”.
Input: str = “abcbca”, patt = “aabc”
Approach: Count the frequency of all the characters of str and patt and store them in arrays strFreq and pattFreq respectively. Now any character ch which appears in patt can be used in a maximum of strFreq[ch] / pattFreq[ch] words and the minimum of this value among all the characters of patt is the required answer.
Below is the implementation of the above approach:
- Lexicographically smallest string formed by appending a character from first K characters of a string | Set 2
- Lexicographically smallest string formed by appending a character from the first K characters of a given string
- Check whether second string can be formed from characters of first string
- Largest sub-string where all the characters appear at least K times
- Lexicographically largest string formed from the characters in range L and R
- Remove characters from string that appears strictly less than K times
- Find the number of strings formed using distinct characters of a given string
- Count of strings that can be formed from another string using each character at-most once
- Count of 1-bit and 2-bit characters in the given binary string
- Count pairs of characters in a string whose ASCII value difference is K
- Count characters in a string whose ASCII values are prime
- Count number of substrings of a string consisting of same characters
- Check whether count of distinct characters in a string is Prime or not
- Count the nodes of a tree whose weighted string does not contain any duplicate characters
- Longest sub string of 0's in a binary string which is repeated K times
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.