3838. Weighted Word Mapping Easy
1/**
2 * [3838] Weighted Word Mapping
3 *
4 * You are given an array of strings words, where each string represents a word containing lowercase English letters.
5 * You are also given an integer array weights of length 26, where weights[i] represents the weight of the i^th lowercase English letter.
6 * The weight of a word is defined as the sum of the weights of its characters.
7 * For each word, take its weight modulo 26 and map the result to a lowercase English letter using reverse alphabetical order (0 -> 'z', 1 -> 'y', ..., 25 -> 'a').
8 * Return a string formed by concatenating the mapped characters for all words in order.
9 *
10 * <strong class="example">Example 1:
11 * <div class="example-block">
12 * Input: <span class="example-io">words = ["abcd","def","xyz"], weights = [5,3,12,14,1,2,3,2,10,6,6,9,7,8,7,10,8,9,6,9,9,8,3,7,7,2]</span>
13 * Output: <span class="example-io">"rij"</span>
14 * Explanation:
15 *
16 * The weight of "abcd" is 5 + 3 + 12 + 14 = 34. The result modulo 26 is 34 % 26 = 8, which maps to 'r'.
17 * The weight of "def" is 14 + 1 + 2 = 17. The result modulo 26 is 17 % 26 = 17, which maps to 'i'.
18 * The weight of "xyz" is 7 + 7 + 2 = 16. The result modulo 26 is 16 % 26 = 16, which maps to 'j'.
19 *
20 * Thus, the string formed by concatenating the mapped characters is "rij".
21 * </div>
22 * <strong class="example">Example 2:
23 * <div class="example-block">
24 * Input: <span class="example-io">words = ["a","b","c"], weights = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]</span>
25 * Output: <span class="example-io">"yyy"</span>
26 * Explanation:
27 * Each word has weight 1. The result modulo 26 is 1 % 26 = 1, which maps to 'y'.
28 * Thus, the string formed by concatenating the mapped characters is "yyy".
29 * </div>
30 * <strong class="example">Example 3:
31 * <div class="example-block">
32 * Input: <span class="example-io">words = ["abcd"], weights = [7,5,3,4,3,5,4,9,4,2,2,7,10,2,5,10,6,1,2,2,4,1,3,4,4,5]</span>
33 * Output: <span class="example-io">"g"</span>
34 * Explanation:
35 * The weight of "abcd" is 7 + 5 + 3 + 4 = 19. The result modulo 26 is 19 % 26 = 19, which maps to 'g'.
36 * Thus, the string formed by concatenating the mapped characters is "g".
37 * </div>
38 *
39 * Constraints:
40 *
41 * 1 <= words.length <= 100
42 * 1 <= words[i].length <= 10
43 * weights.length == 26
44 * 1 <= weights[i] <= 100
45 * words[i] consists of lowercase English letters.
46 *
47 */
48pub struct Solution {}
49
50// problem: https://leetcode.com/problems/weighted-word-mapping/
51// discuss: https://leetcode.com/problems/weighted-word-mapping/discuss/?currentPage=1&orderBy=most_votes&query=
52
53// submission codes start here
54
55impl Solution {
56 pub fn map_word_weights(words: Vec<String>, weights: Vec<i32>) -> String {
57 String::new()
58 }
59}
60
61// submission codes end
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66
67 #[test]
68 fn test_3838() {
69 }
70}
71Back
© 2026 bowen.ge All Rights Reserved.