← Meta Interview Insights

Meta·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Jul 2026

Summary

Meta SWE coding round with a bitmask-style subset problem. Pretty clean problem statement but the edge cases around repeated characters within a single word tripped me up at first.

Questions Asked (1)

Q1

Given a list of words, find the largest subset you can concatenate such that no character appears more than once across the whole concatenated string. Each word itself must also have no repeated characters. Return the maximum total length.

Algorithms & Data Structures
Author's notes

My first instinct was greedy and it was wrong.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model each word as a 26-bit mask of its characters, filtering out any word with internal duplicates. Then use dynamic programming over subsets of characters (or DFS with memoization) to find the maximum total length of concatenated words whose masks are pairwise disjoint. The DP state is the current character mask, and transitions add a word if its mask doesn't overlap.

Pro tip: Mention that the DP over character masks is feasible because there are only 2^26 possible masks, but in practice you can use a hash map to store only reachable states, and you can also prune by sorting words by length descending to find good solutions early. Also, note that the problem is essentially maximum weight independent set on a conflict graph, but the bitmask DP is more efficient here.

1. Preprocess words into bitmasks

For each word, compute a 26-bit integer where each bit represents a letter. If a word has any duplicate character, discard it immediately.

2. Define DP state and transition

Let dp[mask] be the maximum total length achievable using a set of words whose combined character mask is exactly mask. Initialize dp[0] = 0. For each word mask w, update dp[mask | w] = max(dp[mask | w], dp[mask] + len(word)) if (mask & w) == 0.

3. Optimize iteration order

Iterate over all masks from 0 to (1<<26)-1, but only process masks that are reachable (dp[mask] > 0). Alternatively, use a hash map to store only reachable states to save memory and time.

4. Track and return the maximum

Keep a variable max_len updated whenever dp[mask] is updated. After processing all words, return max_len.

5. Analyze complexity and discuss trade-offs

Time complexity is O(N * 2^26) in the worst case, but with reachable states it's much less. Space is O(2^26) for the DP array, which can be reduced using a hash map. Mention that for large N, this is still efficient because 2^26 is about 67 million, which is borderline but manageable with optimizations.

Key Points to Mention

  • Bitmask representation of character sets for O(1) overlap checks.
  • Filtering out words with duplicate characters as a preprocessing step.
  • Dynamic programming over subsets of characters (or reachable states) to maximize total length.
  • The problem is equivalent to finding a maximum weight independent set in a conflict graph, but bitmask DP is more practical.
  • Complexity analysis: O(N * 2^26) worst-case time, but often much faster due to sparse reachable states.
  • Potential optimization: sort words by length descending to find good solutions early and prune, or use a hash map for DP states.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.