java.lang.Object
g1201_1300.s1255_maximum_score_words_formed_by_letters.Solution

public class Solution extends Object
1255 - Maximum Score Words Formed by Letters.<p>Hard</p> <p>Given a list of <code>words</code>, list of single <code>letters</code> (might be repeating) and <code>score</code> of every character.</p> <p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two or more times).</p> <p>It is not necessary to use all characters in <code>letters</code> and each letter can only be used once. Score of letters <code>'a'</code>, <code>'b'</code>, <code>'c'</code>, &hellip; ,<code>'z'</code> is given by <code>score[0]</code>, <code>score[1]</code>, &hellip; , <code>score[25]</code> respectively.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> words = [&ldquo;dog&rdquo;,&ldquo;cat&rdquo;,&ldquo;dad&rdquo;,&ldquo;good&rdquo;], letters = [&ldquo;a&rdquo;,&ldquo;a&rdquo;,&ldquo;c&rdquo;,&ldquo;d&rdquo;,&ldquo;d&rdquo;,&ldquo;d&rdquo;,&ldquo;g&rdquo;,&ldquo;o&rdquo;,&ldquo;o&rdquo;], score = [1,0,9,5,0,0,3,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0]</p> <p><strong>Output:</strong> 23</p> <p><strong>Explanation:</strong></p> <p>Score a=1, c=9, d=5, g=3, o=2</p> <p>Given letters, we can form the words &ldquo;dad&rdquo; (5+1+5) and &ldquo;good&rdquo; (3+2+2+5) with a score of 23.</p> <p>Words &ldquo;dad&rdquo; and &ldquo;dog&rdquo; only get a score of 21.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> words = [&ldquo;xxxz&rdquo;,&ldquo;ax&rdquo;,&ldquo;bx&rdquo;,&ldquo;cx&rdquo;], letters = [&ldquo;z&rdquo;,&ldquo;a&rdquo;,&ldquo;b&rdquo;,&ldquo;c&rdquo;,&ldquo;x&rdquo;,&ldquo;x&rdquo;,&ldquo;x&rdquo;], score = [4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,10]</p> <p><strong>Output:</strong> 27</p> <p><strong>Explanation:</strong></p> <p>Score a=4, b=4, c=4, x=5, z=10</p> <p>Given letters, we can form the words &ldquo;ax&rdquo; (4+5), &ldquo;bx&rdquo; (4+5) and &ldquo;cx&rdquo; (4+5) with a score of 27.</p> <p>Word &ldquo;xxxz&rdquo; only get a score of 25.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> words = [&ldquo;leetcode&rdquo;], letters = [&ldquo;l&rdquo;,&ldquo;e&rdquo;,&ldquo;t&rdquo;,&ldquo;c&rdquo;,&ldquo;o&rdquo;,&ldquo;d&rdquo;], score = [0,0,1,1,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0]</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong> Letter &ldquo;e&rdquo; can only be used once.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= words.length <= 14</code></li> <li><code>1 <= words[i].length <= 15</code></li> <li><code>1 <= letters.length <= 100</code></li> <li><code>letters[i].length == 1</code></li> <li><code>score.length == 26</code></li> <li><code>0 <= score[i] <= 10</code></li> <li><code>words[i]</code>, <code>letters[i]</code> contains only lower case English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maxScoreWords

      public int maxScoreWords(String[] words, char[] letters, int[] score)