Array ( [0] => [1] => questions [2] => Basic [3] => Vowel-or-Consonant )
Given a word. Need to print the vowels and consonants of the given word
First line contains a word.
Print Vowel: vowels of a word separated by space Print Consonant: Consonants of a word separated by space
Inquisitive
Vowels: I U I I I E Consonants: N Q S T V
Boundless
Vowels: O U E Consonants: B N D L S S
Knowledge
Vowels: O E E Consonants: K N W L D G
Login to see Discussion
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.
Login to see Solution