2
# O(S * T); S := len(startWors); T := len(targetWords)5
def wordCount(self, startWords: List[str], targetWords: List[str]) -> int:7
for target in targetWords:8
for start in startWords:10
len(target) - len(start) == 111
and len(set(list(target)) - set(list(start))) == 118
# Sort + HashSet Lookup21
def wordCount(self, startWords: List[str], targetWords: List[str]) -> int:22
# Sort each start word and add it to a hash set23
startWords_sorted = set()25
for word in startWords:26
startWords_sorted.add("".join(sorted(list(word))))28
# sort each target word and add it to a list30
targetWords_sorted = []31
for word in targetWords:32
targetWords_sorted.append(sorted(list(word)))34
# for each sorted target word, we remove a single character and35
# check if the resulting word is in the startWords_sorted36
# if it is, we increment cnt and break the inner loop37
# otherwise we keep removing until we either find a hit or reach the41
for target in targetWords_sorted:42
for i in range(len(target)):43
w = target[:i] + target[i + 1 :]45
if w in startWords_sorted:54
# Similar algorithm as the one above, implemented using a bit mask to avoid the sorts56
def wordCount(self, startWords: List[str], targetWords: List[str]) -> int:59
for word in startWords:62
i = ord(ch) - ord("a")68
for word in targetWords:71
i = ord(ch) - ord("a")75
i = ord(ch) - ord("a")76
if m ^ (1 << i) in start_set: