JavaEasyStrings10 min
Count vowels and consonants
Print vowel and consonant counts separated by a space. Count only English letters; vowels are a,e,i,o,u in either case. Follow the stated ordering and edge-case conventions exactly. Interviewers use this task to probe boundary handling and collection selection.
Input
One line of text, possibly empty.
Output
Print vowel and consonant counts separated by a space. Count only English letters; vowels are a,e,i,o,u in either case.
Constraints
0 <= line length <= 10000; ASCII text.
Example
Input
Hello World!
Output
3 7
Example 2 input
Java QA
Output
3 3
This example exercises a further boundary or ordering case.
Public test cases (2)
Input
Hello World!
Expected output
3 7
Input
AEIOU xyz
Expected output
5 3
Hints (2)
- Identify the state needed to avoid recomputing work for each element.
- Scan once, classifying ASCII letters while ignoring punctuation and digits.
Target complexity: time O(n) · space O(1)
