Array ( [0] => [1] => questions [2] => Basic [3] => Vowel-or-Consonant ) Basic | Vowel or Consonant | THE INQUISITIVE





Vowel or Consonant

LEVEL:Beginner

Description

Given a word. Need to print the vowels and consonants of the given word

Input Format

First line contains a word.

Output Format

Print Vowel: vowels of a word separated by space Print Consonant: Consonants of a word separated by space


Example 1:

Input
Inquisitive
Output
Vowels: I U I I I E
Consonants: N Q S T V	
Example 2:

Input
Boundless			
Output
Vowels: O U E	
Consonants: B N D L S S
Example 3:

Input
Knowledge
Output
Vowels: O E E
Consonants: K N W L D G

oops

Login to see Discussion




Approach

For finding vowels
Step-i) create an empty string to store the vowels in in
Step-ii)convert the given string to the upper case (it is only for the sake of simplicity)
Step-iii) traverse the string and check if any character matches with A E I O or U
Step-iv) if it matches append them to the empty string
Step-v) return the string

Time Complexity: O(n)
Space Complexity: O(n)

For finding consonants
Step-i) create an empty string to store the vowels in in
Step-ii)convert the given string to the upper case (it is only for the sake of simplicity)
Step-iii) traverse the string and check if any character does not match with any vowel
Step-iv) if it does not matches append them to the empty string.
Step-v) return the string


Note :

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

oops

Login to see Solution