1255. Maximum Score Words Formed by Letters
1255. Maximum Score Words Formed by Letters
Description
Given a list of words
, list of singleletters
(might be repeating)and score
of every character.
Return the maximum score of any valid set of words formed by using the given letters (words[i]
cannot be used twoor more times).
It is not necessary to use all characters in letters
and each letter can only be used once. Score of letters'a'
, 'b'
, 'c'
, … ,'z'
is given byscore[0]
, score[1]
, … , score[25]
respectively.
Example 1:
1 | Input: words = ["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] |
Example 2:
1 | Input: words = ["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] |
Example 3:
1 | Input: words = ["leetcode"], letters = ["l","e","t","c","o","d"], 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] |
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.
Hints/Notes
- dfs
Solution
Language: C++
1 | class Solution { |