Given a string s, count special substrings in it. A Substring of S is said to be special if either of the following properties is satisfied.
- It starts with a vowel and ends with a consonant.
- It starts with a consonant and ends with a vowel.
Input : S = "aba" Output : 2 Substrings of S are : a, ab, aba, b, ba, a Out of these only 'ab' and 'ba' satisfy the condition for special Substring. So the answer is 2. Input : S = "adceba" Output : 9
A simple solution is to generate all substrings. For every substring check the condition of special string. If yes increment count.
An efficient solution is to count vowels and consonants in every suffix of string. After counting these, we traverse string from beginning. For every consonant, we add number of vowels after it to result. Similarly, for every vowel, we add number of consonants after it.
- Case conversion (Lower to Upper and Vice Versa) of a string using BitWise operators in C/C++
- Arrangement of words without changing the relative position of vowel and consonants
- Check whether all the substrings have number of vowels atleast as that of consonants
- Find the starting indices of the substrings in string (S) which is made by concatenating all words from a list(L)
- Replace consonants with next immediate consonants alphabetically in a String
- Alternate vowel and consonant string
- Check if the given string is vowel prime
- Count of words ending at the given suffix in Java
- Lexicographically first alternate vowel and consonant string
- Count of adjacent Vowel Consonant Pairs
- Print all Subsequences of String which Start with Vowel and End with Consonant.
- Python program to check if given string is vowel Palindrome
- Replace all consonants with nearest vowels in a string
- Modify string by removing vowels in between two consonants
- Count consonants in a string (Iterative and recursive methods)
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.
Improved By : Rajput-Ji