Count Valid Words for Each Daily Letter Puzzle Using Bitmasks
Last updated: November 29, 2026
Quick Overview
Each daily word puzzle is 7 distinct letters with one required center letter. A word is valid for a puzzle if it contains the center letter and uses only the puzzle's letters. Given 10^5 words and 10^4 puzzles, return how many words are valid for each puzzle.
Meta
November 29, 20260
0
0 solved
Each daily word puzzle is 7 distinct letters with one required center letter. A word is valid for a puzzle if it contains the center letter and uses only the puzzle's letters. Given 10^5 words and 10^4 puzzles, return how many words are valid for each puzzle.
A Meta onsite question that rewards turning sets of letters into 26-bit masks and enumerating submasks. The interviewer expects you to rule out the O(words x puzzles) comparison and exploit the small puzzle size: only 2^6 submasks per puzzle.
What the Interviewer Expects
- Encode each word as a 26-bit letter mask
- Count words per distinct mask in a hash map
- For each puzzle, enumerate submasks of its 6 non-center letters
- Add the center letter to each submask and sum counts
- Explain the 2^6 per-puzzle bound
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What if puzzles have 12 letters instead of 7?
- How would you list the words, not just count them?
- How would you precompute answers for every possible puzzle?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: words (up to 10^5, lowercase, length up to 50) and puzzles (up to 10^4, exactly 7 distinct letters, the first letter is the required center). Output: list where entry i counts words valid f...
High-Level Design
A word's validity depends only on its set of letters, so map each word to a 26-bit mask and count masks: freq[mask] += 1. Words whose mask has more than 7 bits can never match and can be skipped.
F...