2025-09-15 15:04:52 +0000 UTC

Maximum Number of Words You Can Type

Code

class Solution:
    def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
        ignore = False
        res = 0
        for char in itertools.chain(text, " "):
            if char == " ":
                if ignore:
                    ignore = False
                else:
                    res += 1
            elif char in brokenLetters:
                ignore = True
        return res