882. Count Vowels, Consonants, and Spaces in a String
Given a string str, write a function to count the number of vowels, consonants, and whitespace characters in the string.
Return the result as an array of three integers: [vowel_count, consonant_count, space_count].
Example 1:
Input: str = "Take u forward is Awesome"
Output: [10, 11, 4]
Explanation:
- Vowels: a, e, u, o, a, i, A, e, o, e → 10
- Consonants: T, k, f, r, w, r, d, s, w, s, m → 11
- Spaces: 4
Example 2:
Input: str = "India won the cricket match"
Output: [8, 15, 4]
Explanation:
- Vowels: I, i, a, o, e, i, e, a → 8
- Consonants: n, d, w, n, t, h, c, r, c, k, t, m, t, c, h → 15
- Spaces: 4
Now Your Turn!
Pick the correct output for the given inputInput: str = "A E I O U"
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= str.length <= 104
- String may contain uppercase and lowercase letters and spaces only.
- Ignore digits, symbols, and punctuation (if present).