#3136
Easy Algorithms Valid word
String
50.9% acceptance
Feb 24, 2026
480
169
A word is considered valid if:
It contains a minimum of 3 characters.
It contains only digits (0-9), and English letters (uppercase and lowercase).
It includes at least one vowel.
It includes at least one consonant.
You are given a string word.
Return true if word is valid, otherwise, return false.
Notes:
'a', 'e', 'i', 'o', 'u', and their uppercases are vowels.
A consonant is an English letter that is not a vowel.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn is_valid(word: String) -> bool {
if word.len() < 3 {
return false;
}
let vowels = b"aeiouAEIOU";
let mut has_vowel = false;
let mut has_consonant = false;
for &b in word.as_bytes() {
if b.is_ascii_alphanumeric() {
if vowels.contains(&b) {
has_vowel = true;
} else if b.is_ascii_alphabetic() {
has_consonant = true;
}
} else {
return false;
}
}
has_vowel && has_consonant
}
}