Step-by-Step
Given an array of strings words and an integer array weights of length 26. The weight of a word is the sum of the weights of its characters. 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'). Return the concatenated string.
Words Array
Weights Array (a-z)
Mapping & Result
Step log
| 1 | def solve(words, weights): |
| 2 | res = [] |
| 3 | for w in words: |
| 4 | weight_sum = 0 |
| 5 | for c in w: |
| 6 | weight_sum += weights[ord(c) - ord('a')] |
| 7 | mapped_val = weight_sum % 26 |
| 8 | res.append(chr(ord('z') - mapped_val)) |
| 9 | return ''.join(res) |
Test Cases
Basic case
Input Configuration
Ensure exactly 26 weights are provided.
Animation Controls
Complexity Analysis
O(N)
O(N)
Where N is the total number of characters across all words. We iterate through each character once.