Count Consonants in String
Explore how to count consonants in a string by applying both iterative and recursive techniques. Learn to differentiate vowels from consonants and handle special cases like spaces and punctuation. This lesson helps you understand string manipulation with recursion and iteration while considering time complexity for efficient solutions.
We'll cover the following...
In this lesson, we focus on the following problem:
Given a string, calculate the number of consonants present.
The vowels are the following letters:
a e i o u
Any other letter that is not a vowel is a consonant.
Let’s have a look at an example:
Welcome to Educative!
has 9 consonants.
Before you dive into the implementation, consider the edge cases such as spaces and exclamation marks. This implies that if a character is not a vowel, it has to be a letter to be considered a consonant.
Iterative Approach
Check out the ...
On line 1, we define ...