Leetcode 1935: Maximum Number of Words You Can Type

grid47
grid47
Exploring patterns and algorithms
Apr 27, 2024 5 min read

You are given a string ’text’ consisting of words separated by a single space and a string ‘brokenLetters’ containing the broken keys on a malfunctioning keyboard. Return the number of words in ’text’ that can be fully typed using the working keys.
Problem
Approach
Steps
Complexity
Input: The input consists of two strings: 'text' containing words separated by spaces, and 'brokenLetters' containing distinct lowercase English letters.
Example: text = "apple orange", brokenLetters = "a"
Constraints:
• 1 <= text.length <= 10^4
• 0 <= brokenLetters.length <= 26
• text consists of words separated by a single space without leading or trailing spaces.
• Each word only consists of lowercase English letters.
• brokenLetters consists of distinct lowercase English letters.
Output: Return the number of words in 'text' that can be fully typed using the working keys.
Example: 1
Constraints:
Goal: To count the number of words in 'text' that do not contain any broken letters.
Steps:
• Iterate over each word in 'text'.
• For each word, check if it contains any letter from 'brokenLetters'.
• If a word can be fully typed (contains no broken letters), increment the count.
Goal: We need an efficient solution that works with text lengths up to 10^4.
Steps:
• The text string will have a length between 1 and 10,000.
• The brokenLetters string will contain distinct lowercase English letters (0 to 26 characters).
Assumptions:
• The text string is guaranteed to have words separated by single spaces.
• The brokenLetters string can be empty, which means all letters are usable.
Input: text = "apple orange", brokenLetters = "a"
Explanation: The word 'apple' cannot be typed because it contains the broken letter 'a', but 'orange' can be typed. Hence, the output is 1.

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus