Maximum Number of Words You Can Type
We are given a string text
representing words and a string brokenLetters
representing the keys that are broken. We need to find the number of words in text
that can be typed using this keyboard.
Here’s the code to solve this problem:
- Split the text into words.
- Check if each word contains any of the broken letters.
- Increment the count if the word does not contain any broken letters.
- Return the count.
|
|
Explanation:
- We start by converting
brokenLetters
into a set to make the lookup operation efficient. - We split
text
into words using thesplit
method. - We then iterate through each word and use the
all
function combined with a generator expression to check if the word does not contain any of the broken letters. - If the word passes the check, we increment the counter.
- Finally, we return the counter as the result.