1255. Maximum Score Words Formed by Letters Hard
1/**
2 * [1255] Maximum Score Words Formed by Letters
3 *
4 * Given a list of words, list of single letters (might be repeating) and score of every character.
5 * Return the maximum score of any valid set of words formed by using the given letters (words[i] cannot be used two or more times).
6 * 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 by score[0], score[1], ... , score[25] respectively.
7 *
8 * Example 1:
9 *
10 * 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]
11 * Output: 23
12 * Explanation:
13 * Score a=1, c=9, d=5, g=3, o=2
14 * Given letters, we can form the words "dad" (5+1+5) and "good" (3+2+2+5) with a score of 23.
15 * Words "dad" and "dog" only get a score of 21.
16 * Example 2:
17 *
18 * 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]
19 * Output: 27
20 * Explanation:
21 * Score a=4, b=4, c=4, x=5, z=10
22 * Given letters, we can form the words "ax" (4+5), "bx" (4+5) and "cx" (4+5) with a score of 27.
23 * Word "xxxz" only get a score of 25.
24 * Example 3:
25 *
26 * 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]
27 * Output: 0
28 * Explanation:
29 * Letter "e" can only be used once.
30 *
31 * Constraints:
32 *
33 * 1 <= words.length <= 14
34 * 1 <= words[i].length <= 15
35 * 1 <= letters.length <= 100
36 * letters[i].length == 1
37 * score.length == 26
38 * 0 <= score[i] <= 10
39 * words[i], letters[i] contains only lower case English letters.
40 *
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/maximum-score-words-formed-by-letters/
45// discuss: https://leetcode.com/problems/maximum-score-words-formed-by-letters/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50 pub fn max_score_words(words: Vec<String>, letters: Vec<char>, score: Vec<i32>) -> i32 {
51 0
52 }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59 use super::*;
60
61 #[test]
62 fn test_1255() {
63 }
64}
65
Back
© 2025 bowen.ge All Rights Reserved.