Given a string str. The task is to find all possible number of strings that can be obtained by replacing the “$” with alphabets in the given string.
Note: Alphabets should be placed in such a way that the string is always alternating in vowels and consonants, and the string must always start with a consonant. It is assumed that such a string is always possible, i.e. there is no need to care about the characters other than “$”.
Input: str = "y$s" Output: 5 $ can be replaced with any of the 5 vowels. So, there can be 5 strings. Input: str = "s$$e$" Output: 2205
Approach: It is given that the string will start with a consonant. So, if ‘$’ is at even position(considering 0-based indexing) then there should be a consonant else there should be a vowel. Also, given that there is no need to care about the characters other than “$”, i.e., characters other than “$” are placed correctly in the string maintaining the alternating consonant and vowel sequence. Let us understand the problem with an example.
str = “s$$e$”
Here we have to find the number of ways to form a string with given constraints.
- First occurence of $ is at 2nd position i.e. 1st index, so we can use 5 vowels.
- Second occurence of $ is at 3rd position, so we can use 21 consonants.
- Third occurence of $ is at 5th position, so we can use 21 consonants.
So, total number of ways to form above string is = 5*21*21 = 2205
Below is the implementation of the above approach:
- Modify string by removing vowels in between two consonants
- Replace all consonants with nearest vowels in a string
- Arrange consonants and vowels nodes in a linked list
- Encrypt string with product of number of vowels and consonants in substring of size k
- Arrangement of words without changing the relative position of vowel and consonants
- Count consonants in a string (Iterative and recursive methods)
- Replace consonants with next immediate consonants alphabetically in a String
- Program to count vowels in a string (Iterative and Recursive)
- Count the number of vowels occurring in all the substrings of given string
- Python program to count number of vowels using sets in given string
- Program to count vowels, consonant, digits and special characters in string.
- Count characters at same position as in English alphabet
- Count Derangements (Permutation such that no element appears in its original position)
- Count All Palindrome Sub-Strings in a String | Set 2
- Count All Palindrome Sub-Strings in a String | Set 1
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.