Magicsheet logo

Maximum Score Words Formed by Letters

Hard
44.3%
Updated 6/1/2025

Maximum Score Words Formed by Letters

1. What is this problem about?

The Maximum Score Words Formed by Letters coding problem asks you to select a subset of words from a given list to maximize your total score. You are limited by a collection of available letters, each having a specific count. Each letter also has an associated score. You can only form a word if you have enough instances of its required letters in your collection.

2. Why is this asked in interviews?

This "Hard" problem is a favorite at Infosys, Meta, and Google because it tests a candidate's ability to explore a combinatorial search space. Since the number of words is typically small (around 14), it's a perfect scenario for backtracking or bitmasking. It evaluates your skill in resource management and your ability to prune search branches that are no longer viable.

3. Algorithmic pattern used

This problem utilizes the Backtracking and Bitmask interview pattern. You can represent each subset of words using a bitmask (where the i-th bit is 1 if the i-th word is included). For each mask, you check if the combined letter requirements of the selected words exceed your available counts. Alternatively, you can use a recursive backtracking approach (Pick or Don't Pick) to explore all valid word combinations.

4. Example explanation

Words: ["cat", "dog", "dad"], Letters: {c:1, a:1, t:1, d:2, o:1, g:1}, Scores: {a:1, c:1, d:2, g:2, o:2, t:1}.

  • Option 1: "cat" (score 3) + "dog" (score 6) = 9. Total letters used: {c, a, t, d, o, g}. (Valid).
  • Option 2: "dad" (score 5). Total letters: {d, a, d}. (Valid).
  • Option 3: "dog" + "dad" = 11. Total letters: {d, o, g, d, a, d}. (Invalid, need 3 'd's but only have 2). The maximum score is 9.

5. Common mistakes candidates make

A common error is not correctly backtracking the letter counts after a recursive call, leading to "over-counting" errors. Another mistake is forgetting to handle words that cannot be formed at all due to missing letters. Some candidates also struggle with efficiency, not realizing that with only 14 words, an exponential solution is perfectly acceptable.

6. Interview preparation tip

For "Bitmask, Backtracking interview pattern" problems, always check the constraints. If the input size is small (N < 20), an exponential solution is likely intended. Practice managing state (like a frequency map of available letters) across recursive calls to ensure your implementation is clean and bug-free.

Similar Questions