Maximum Score Words Formed by Letters

Given a list of words, a list of single-character letters that might contain repeats, and score, where score gives the value of every character.

Return the maximum score of any valid set of words formed by using the given letters. Each words[i] cannot be used two or more times.

It is not necessary to use all characters in letters, and each letter can only be used once. The scores of letters 'a', 'b', 'c', ..., 'z' are given by score[0], score[1], ..., score[25], respectively.

Example 1
Inputwords = ["dog","cat","dad","good"], letters = ["a","a","c","d","d","d","g","o","o"], 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]
Output23
We can form the words "dad" with score 11 and "good" with score 12, for a total score of 23.
Example 2
Inputwords = ["xxxz","ax","bx","cx"], letters = ["z","a","b","c","x","x","x"], 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]
Output27
We can form the words "ax", "bx", and "cx", each with score 9, for a total score of 27.

Constraints

  • 1 <= words.length <= 14
  • 1 <= words[i].length <= 15
  • 1 <= letters.length <= 100
  • letters[i].length == 1
  • score.length == 26
  • 0 <= score[i] <= 10
  • words[i], letters[i] contains only lower case English letters.

Asked at 4 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate