FastPrepCount Vowels and Consonants

Count Vowels and Consonants

Mygate logoMygate● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Given an ASCII string s, return [vowels, consonants], the counts of vowels and consonants among its English letters.

Treat uppercase and lowercase letters alike. The vowels are a, e, i, o, and u. Every other English letter, including y, is a consonant. Ignore digits, punctuation, and whitespace.

An empty string or a string without letters produces [0,0].

Function

countVowelsConsonants(s: String) → int[]

Examples

Example 1

s = "Hello, World!"return = [3,7]

The vowels are e, o, and o. The other seven letters are consonants; punctuation and the space are ignored.

Example 2

s = "AEIOUaeiou 123!"return = [10,0]

Both cases of all five vowels count; digits and punctuation do not.

Constraints

  • 0 ≤ s.length ≤ 100,000.
  • s contains ASCII characters.

More Mygate problems

See Mygate hiring insights
public int[] countVowelsConsonants(String s) {
    // write your code here
}
s"Hello, World!"
expected[3,7]
Checking account…