There is a string text consisting of words separated by a single space, and a string brokenLetters containing unique broken keyboard letters. A word can be typed if none of its letters are in brokenLetters. Return the number of words in text that can be typed.
text into words by spaces.Example Input: text = “hello world”, brokenLetters = “ad”
Step-by-step execution:
public class Solution {
public int canBeTypedWords(String text, String brokenLetters) {
boolean[] charExists = new boolean[26];
for (char c : brokenLetters.toCharArray()) {
charExists[c - 'a'] = true;
}
String[] textArr = text.split(" ");
int count = 0;
for (String word : textArr) {
boolean canType = true;
for (int i = 0; i < word.length(); i++) {
if (charExists[word.charAt(i) - 'a']) {
canType = false;
break;
}
}
if (canType) {
count++;
}
}
return count;
}
}
text, m = length of brokenLetters