Skip to content

Instantly share code, notes, and snippets.

@Ifihan
Created September 15, 2025 22:37
Show Gist options
  • Select an option

  • Save Ifihan/48f16adbaeba197c32041c0ced226fc2 to your computer and use it in GitHub Desktop.

Select an option

Save Ifihan/48f16adbaeba197c32041c0ced226fc2 to your computer and use it in GitHub Desktop.
Maximum Number of Words You Can Type

Question

Approach

I split the text into words and check each one to see if it contains any broken letters. If a word contains a broken letter, it cannot be typed, so I skip it. Otherwise, I count it as typeable. To make the check fast, I put all broken letters into a set for O(1) membership tests.

Implementation

class Solution:
    def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
        broken = set(brokenLetters)
        count = 0
        for word in text.split():
            if all(ch not in broken for ch in word):
                count += 1
        return count

Complexities

  • Time: O(n)
  • Space: O(b) where b is number of broken letter (26 max)
image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment