Practice Number of Valid Words for Each Puzzle
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Number of Valid Words for Each Puzzle
Problem Statement
For each puzzle, count the words that use only letters found in that puzzle and also contain its first letter. A letter may repeat inside a word. Return one count per puzzle, retaining the puzzle order and counting each qualifying word-list entry. Each puzzle contains seven distinct lowercase letters. Practice approach: Convert each word to a 26-bit letter mask and count identical masks. A mask with more than seven set bits cannot qualify. For a puzzle, enumerate the subsets of its six noninitial letters and combine each with the required initial-letter bit. Sum their stored frequencies. This checks 64 masks per puzzle instead of scanning every word again.
Source: Number of Valid Words for Each Puzzle on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
words = ["aaaa","asas","able","ability","actt","actor","access"], puzzles = ["aboveyz","abrodyz","abslute","absoryz","actresz","gaswxyz"]
[1,1,3,2,4,0]
# Example 2
words = ["apple","pleas","please"], puzzles = ["aelwxyz","aelpxyz","aelpsxy","saelpxy","xaelpsy"]
[0,1,3,2,0]
Constraints
Related LeetCode Problems
Practice more problems similar to Number of Valid Words for Each Puzzle.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.