#1935
Easy Algorithms Maximum number of words you can type
Hash Table String
82.9% acceptance
Feb 25, 2026
994
40
There is a malfunctioning keyboard where some letter keys do not work. All other keys on the keyboard work properly.
Given a string text of words separated by a single space (no leading or trailing spaces) and a string brokenLetters of all distinct letter keys that are broken, return the number of words in text you can fully type using this keyboard.
Solution
Rust
Time O(n)
Space O(1)
impl Solution {
pub fn can_be_typed_words(text: String, broken_letters: String) -> i32 {
let broken: std::collections::HashSet<u8> = broken_letters.bytes().collect();
text.split(' ')
.filter(|w| !w.bytes().any(|b| broken.contains(&b)))
.count() as i32
}
}