Subsets & Combinations - Number of Valid Words for Each Puzzle
Examine the following code snippet from the bitmask + hash map solution. Which line contains a subtle bug that causes incorrect counts?
```python
def findNumOfValidWords(words, puzzles):
freq = {}
for word in words:
mask = 0
for ch in set(word):
mask |= 1 << (ord(ch) - ord('a'))
if bin(mask).count('1') <= 7:
freq[mask] = freq.get(mask, 0) + 1
res = []
for puzzle in puzzles:
first = 1 << (ord(puzzle[0]) - ord('a'))
count = 0
def backtrack(i, mask):
nonlocal count
if i == len(puzzle):
if mask in freq and (mask & first):
count += freq[mask]
return
backtrack(i + 1, mask)
backtrack(i + 1, mask | (1 << (ord(puzzle[i]) - ord('a'))))
backtrack(1, 0)
res.append(count)
return res
```
