All problems
1022EasyString

Is the Token Well Formed

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3136Valid Word

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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