FastPrepToken Validation

Token Validation

Rippling logoRippling● EasyFULLTIMEOA
Learn

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 3 characters.
  • Every character is an ASCII letter or decimal digit.
  • It contains at least one vowel: a, e, i, o, or u, 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) → int

Examples

Example 1

tokenString = "This is an example string 234."return = 3

The 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 = 2

a1b 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 = 0

AEI 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.

More Rippling problems

See Rippling hiring insights
public int countValidTokens(String tokenString) {
    // Write your code here.
}
tokenString"This is an example string 234."
expected3
Checking account…