Given an English word of length at most 20 characters. Calculate the number of ways to arrange the word such that no vowels occur together.
Note : If the total number of vowels in the given word is one then the result should be 0.
Input : allahabad Output : 7200 Input : geeksforgeeks Output : 32205600 Input : abcd Output : 0
Since the word contains vowels and consonants. Calculate the total number of ways to arrange the given word and subtract the number of ways having all vowels together. To calculate the total number of ways we’ll use the following formula-
No of ways = (n!) / (r1! * r2! * ... * rk!)
Where n is the number of different characters in the word and r1, r2 … rk, are the frequency of same type character.
In order to calculate the number of ways such that all vowels occur together, we consider the group of all vowels as a single character and using the above formula we’ll calculate the total number of ways having all vowel together. Now subtract it from the total number of ways to get the result.
Below is the implementation of the above approach:
7200 32205600 0
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.
- Number of ways to arrange a word such that all vowels occur together
- Count number of ways to arrange first N numbers
- Number of ways to arrange N numbers which are in a range from 1 to K under given constraints.
- Calculate Stirling numbers which represents the number of ways to arrange r objects around n different circles
- Arrange consonants and vowels nodes in a linked list
- Number of ways to arrange K different objects taking N objects at a time
- Arrangement of the characters of a word such that all vowels are at odd places
- Number of ways to arrange 2*N persons on the two sides of a table with X and Y persons on opposite sides
- Find the number of words of X vowels and Y consonants that can be formed from M vowels and N consonants
- Ways to arrange Balls such that adjacent balls are of different types
- Arrange given numbers to form the smallest number
- Find ways to arrange K green balls among N balls such that exactly i moves is needed to collect all K green balls
- Count of substrings consisting of even number of vowels
- Sort an Array of Strings according to the number of Vowels in them
- Check whether all the substrings have number of vowels atleast as that of consonants
- Count the number of vowels occurring in all the substrings of given string
- Number of words that can be made using exactly P consonants and Q vowels from the given string
- Lexicographically smallest K-length substring containing maximum number of vowels
- Encrypt string with product of number of vowels and consonants in substring of size k
- Count number of rotated strings which have more number of vowels in the first half than second half
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.