VOOZH about

URL: https://www.geeksforgeeks.org/dsa/count-consonants-string-iterative-recursive-methods/

⇱ Count consonants in a string (Iterative and recursive methods) - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Count consonants in a string (Iterative and recursive methods)

Last Updated : 20 Feb, 2023

Given a string, count total number of consonants in it. A consonant is an English alphabet character that is not vowel (a, e, i, o and u). Examples of constants are b, c, d, f, and g.

Examples : 

Input : abc de
Output : 3
There are three consonants b, c and d.

Input : geeksforgeeks portal
Output : 12

 1. Iterative Method 


Output
3

Time Complexity: O(n), where n is the length of the string
Auxiliary Space: O(1)

 2. Recursive Method 


Output
3

Time Complexity: O(n), where n is the length of the string
Auxiliary Space: O(n), due to recursive call stacks.

Illustration of recursive method:
 

👁 Image

Comment