Given a string str and two integers P and Q. The task is to find the total count of words that can be formed by choosing exactly P consonants and Q vowels from the given string.
Input: str = “geek”, P = 1, Q = 1
“ge”, “ge”, “eg”, “ek”, “eg”, “ek”,
“ke” and “ke” are the possible words.
Input: str = “crackathon”, P = 4, Q = 3
Approach: Since P consonants and Q vowels has to be chosen from the original count of consonants and vowels in the given string. So, binomial coefficient can be used to calculate the combinations of choosing these characters and the characters chosen can be arranged in themselves using the factorial of their count.
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.
- Find the number of words of X vowels and Y consonants that can be formed from M vowels and N consonants
- Encrypt string with product of number of vowels and consonants in substring of size k
- Modify string by removing vowels in between two consonants
- Replace all consonants with nearest vowels in a string
- Modify the string by swapping continuous vowels or consonants
- Minimum swaps required to move all vowels occurs after consonants in a given string
- Check whether all the substrings have number of vowels atleast as that of consonants
- Arrange consonants and vowels nodes in a linked list
- Longest subsequence consisting of alternate vowels and consonants
- Count strings with consonants and vowels at alternate position
- Replace consonants with next immediate consonants alphabetically in a String
- Arrangement of words without changing the relative position of vowel and consonants
- Count the number of vowels occurring in all the substrings of given string
- Program to remove consonants from a String
- Longest Subsequence of a String containing only Consonants
- Count consonants in a string (Iterative and recursive methods)
- First X vowels from a string
- Reverse vowels in a given string
- Modify the string such that it contains all vowels at least once
- Count the pairs of vowels in the given 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 email@example.com. 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.