### Problem
You are given lowercase English words in `words` and 26 positive integer letter weights. `weights[0]` belongs to `a`, `weights[1]` to `b`, and so on through `z`.
For each word, sum the weights of all its character occurrences. Take that sum modulo 26, then map the residue in reverse alphabetical order:
```text
0 -> z, 1 -> y, 2 -> x, ..., 25 -> a
```
Return the string obtained by concatenating one mapped character per word in the original word order.
```cpp
class Solution {
public:
string mapWordWeights(vector<string>& words, vector<int>& weights);
};
```
### Examples
**Example 1:**
```text
Input: words = ["az","b","aa"], weights = [13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13]
Output: "zmz"
Explanation: The word sums are 26,13,26. Their residues 0,13,0 map to z,m,z.
```
**Example 2:**
```text
Input: words = ["a","bb","cab"], weights = [25,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]
Output: "axx"
Explanation: The sums are 25,2,28. Residues 25,2,2 map to a,x,x. Both copies of b in "bb" contribute their weight.
```
### Constraints
- `1 <= words.length <= 100`.
- `1 <= words[i].length <= 10`.
- Every word contains only lowercase English letters.
- `weights.length == 26`.
- `1 <= weights[i] <= 100`.
### Clarifying Questions
- Do repeated letters contribute repeatedly? Yes.
- Do the weights have to equal alphabet positions? No; use the supplied weights.
- Does residue zero map to `a`? No; it maps to `z` under the reverse mapping.
- May the words be reordered? No; the output follows their given order.
### What a Strong Answer Covers
- The supplied letter weights, character multiplicities, and reverse residue mapping.
- Exactly one output character for each input word, in order.
- Residue zero, residue 25, repeated letters, and sums above 26.
- A correctness argument and numeric and resource bounds.
### Follow-up Questions
- What would need specification if uppercase letters were also accepted?
- How would returning each word's unreduced weight change the output format?
```hint Apply each stated transformation in sequence
For each word, sum weights indexed by its characters. Reduce the sum modulo 26 and index the reversed alphabet with that residue. Reset the sum for the next word and append its mapped character.
```
Overview: Map weighted lowercase words through reverse alphabetical residues. Covers repeated letters, mapping endpoints, fresh examples, proof, and C++ code.
You are given lowercase English words in words and 26 positive integer letter weights. weights[0] belongs to a, weights[1] to b, and so on through z.
For each word, sum the weights of all its character occurrences. Take that sum modulo 26, then map the residue in reverse alphabetical order:
0 -> z, 1 -> y, 2 -> x, ..., 25 -> a
Return the string obtained by concatenating one mapped character per word in the original word order.
class Solution {
public:
string mapWordWeights(vector<string>& words, vector<int>& weights);
};
Examples
Example 1:
Input: words = ["az","b","aa"], weights = [13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13]
Output: "zmz"
Explanation: The word sums are 26,13,26. Their residues 0,13,0 map to z,m,z.
Example 2:
Input: words = ["a","bb","cab"], weights = [25,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]
Output: "axx"
Explanation: The sums are 25,2,28. Residues 25,2,2 map to a,x,x. Both copies of b in "bb" contribute their weight.
Constraints
1 <= words.length <= 100
.
1 <= words[i].length <= 10
.
Every word contains only lowercase English letters.
weights.length == 26
.
1 <= weights[i] <= 100
.
Clarifying Questions Guidance
Do repeated letters contribute repeatedly? Yes.
Do the weights have to equal alphabet positions? No; use the supplied weights.
Does residue zero map to
a
? No; it maps to
z
under the reverse mapping.
May the words be reordered? No; the output follows their given order.
What a Strong Answer Covers Guidance
The supplied letter weights, character multiplicities, and reverse residue mapping.
Exactly one output character for each input word, in order.
Residue zero, residue 25, repeated letters, and sums above 26.
A correctness argument and numeric and resource bounds.
Follow-up Questions Guidance
What would need specification if uppercase letters were also accepted?
How would returning each word's unreduced weight change the output format?