Maximum Number of Words You Can Type - Problem
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.
Input & Output
Example 1 — Basic Case
$
Input:
text = "hello world", brokenLetters = "ad"
›
Output:
1
💡 Note:
We can type "hello" (no 'a' or 'd'), but cannot type "world" (contains 'd'). So 1 word can be typed.
Example 2 — Multiple Broken Letters
$
Input:
text = "leet code", brokenLetters = "lt"
›
Output:
1
💡 Note:
We cannot type "leet" (contains 'l' and 't'), but can type "code" (no 'l' or 't'). So 1 word can be typed.
Example 3 — No Broken Letters
$
Input:
text = "leet code", brokenLetters = ""
›
Output:
2
💡 Note:
No keys are broken, so we can type all words: "leet" and "code". So 2 words can be typed.
Constraints
- 1 ≤ text.length ≤ 104
- 0 ≤ brokenLetters.length ≤ 26
- text consists of words separated by a single space without any leading or trailing spaces
- Each word consists of only lowercase English letters
- brokenLetters consists of distinct lowercase English letters
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code