Count Character Types
Given a string s, determine the number of characters belonging to each of the following categories:
- Vowels: English letters a, e, i, o, u, including their uppercase forms.
- Consonants: All English alphabetic characters other than vowels.
- Digits: Numeric characters from 0 to 9.
- Spaces: Only the ASCII space character (' ').
Return a vector of four integers representing the counts in the following order: [vowels, consonants, digits, spaces]
Note: Each character should be counted in exactly one applicable category. Ignore punctuation and other special characters that do not belong to any of these categories.
Example 1:
Input: s = "Hello World 123"
Output: [3, 7, 3, 2]
Explanation: The string contains 3 vowels (e, o, o), 7 consonants (H, l, l, W, r, l, d), 3 digits (1, 2, 3), and 2 spaces. Therefore, the result is [3, 7, 3, 2].
Example 2:
Input: s = "AEIOU xyz! 90"
Output: [5, 3, 2, 2]
Explanation: The string contains 5 vowels (A, E, I, O, U), 3 consonants (x, y, z), 2 digits (9, 0), and 2 spaces. The special character ! is ignored. Therefore, the result is [5, 3, 2, 2].
Now Your Turn!
Pick the correct output for the given inputInput: s = "aB9 !?"
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 0 <= s.length() <= 105