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.
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.
- 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
- Replace consonants with next immediate consonants alphabetically in a String
- Program to build a DFA that accepts strings starting and ending with different character
- Program to accept Strings starting with a Vowel
- 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)
- Check if a string can be split into substrings starting with N followed by N characters
- 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
- Count of N size strings consisting of at least one vowel and one consonant
- Python program to check if given string is vowel Palindrome
- Count of adjacent Vowel Consonant Pairs
- Check if the given string is vowel prime
- Count pair of strings whose concatenation has every vowel
- Replace every vowels with lexicographically next vowel in a String
- Minimize cost to replace all the vowels of a given String by a single vowel
- Count of words ending at the given suffix in Java
- Encrypt string with product of number of vowels and consonants in substring of size k
Improved By : Rajput-Ji