Token Validation
Problem statement
You are given a string tokenString containing tokens separated by one or more spaces.
A token is valid only when all of the following conditions hold:
- It contains at least
3characters. - Every character is an ASCII letter or decimal digit.
- It contains at least one vowel:
a,e,i,o, oru, ignoring letter case. - It contains at least one consonant, meaning an ASCII letter that is not a vowel.
Digits are allowed, but they are neither vowels nor consonants. Return the number of valid tokens in tokenString. Empty segments created by repeated spaces are ignored.
Function
countValidTokens(tokenString: String) → intExamples
Example 1
tokenString = "This is an example string 234."return = 3The valid tokens are This, example, and string. The tokens is and an are too short, while 234. contains a non-alphanumeric character.
Example 2
tokenString = "a1b 123 bcE9"return = 2a1b and bcE9 each contain a vowel and a consonant. 123 has no letters, so the result is 2.
Example 3
tokenString = "AEI bcd xy!"return = 0AEI has no consonant, bcd has no vowel, and xy! contains a non-alphanumeric character.
Constraints
- For this exercise, assume
1 <= tokenString.length <= 100000. - For this exercise, assume tokens are separated by one or more ASCII space characters.