Show problems as
Classic problem #3136EasyString

Valid Word

Real-world version: Is the Token Well Formed
Tracked in this browser only
Read Valid Word on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A token reads token, made up of English letters in either case, digits, and the marks '@', '#' and '$'.

The token is well formed when all of these hold:

  • it runs to at least three characters;
  • every character is a letter or a digit, so none of the three marks appears anywhere;
  • it holds at least one vowel, meaning 'a', 'e', 'i', 'o' or 'u' in either case;
  • it holds at least one consonant, meaning a letter that is not a vowel.

Return whether the token is well formed.

Examples

Example 1

Input
token = "aB3"
Output
true

Three characters, none of them a mark, with `a` as the vowel and `B` as the consonant. The digit is allowed and counts as neither.

Example 2

Input
token = "xyz"
Output
false

Long enough and free of marks, but every letter is a consonant, so there is no vowel.

Example 3

Input
token = "q@w"
Output
false

The mark in the middle is not allowed, whatever else the token holds.

Constraints

  • 1 <= token.length <= 20
  • Every character of token is an English letter, a digit, or one of '@', '#' and '$'.

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def is_valid(token: str) -> bool:
Java
public boolean isValid(String token)