Given an integer N, which represents the length of a string, the task is to count the number of strings possible of length N which consists of only one vowel and one consonant.
Note: Since the output can be large print in modulo 1000000007
Input: N = 2
There are 5 vowels and 21 consonants in English alphabets.
So for vowel ‘a’ we can have 42 strings of the form ‘ab’, ‘ba’, ‘ac’, ‘ca’, ‘ad’, ‘da’ and so on.
For the other 4 vowels, the same process repeats, and we get a total of 210 such strings.
Input: N = 3
To solve the problem mentioned above, we need to ignore the strings that comprise only vowels(to allow at least one consonant) and only consonants(to allow at least one vowel). Hence, the required answer is:
All N length strings possible – (N length strings consisting of only vowels + N length strings consisting of only consonants) = 26 N – (5 N + 21 N)
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 adjacent Vowel Consonant Pairs
- Alternate vowel and consonant string
- Print all Subsequences of String which Start with Vowel and End with Consonant.
- Lexicographically first alternate vowel and consonant string
- Program to find if a character is vowel or Consonant
- Count of binary strings of given length consisting of at least one 1
- Count pair of strings whose concatenation has every vowel
- Program to count vowels, consonant, digits and special characters in string.
- Sub-strings that start and end with one character and have at least one other
- Program to accept Strings starting with a Vowel
- Maximum count of sub-strings of length K consisting of same characters
- Count of strings that become equal to one of the two strings after one removal
- Replace every consonant sequence with its length in the given string
- Count the nodes of the tree whose weighted string contains a vowel
- Substrings starting with vowel and ending with consonants and vice versa
- Arrangement of words without changing the relative position of vowel and consonants
- Count N-digit numbers possible consisting of digits X and Y
- Python program to check if given string is vowel Palindrome
- Check if the given string is vowel prime
- Replace every vowels with lexicographically next vowel in a 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.