↓Skip to main content
  1. LeetCode/

LeetCode 3838: Weighted Word Mapping

·1 min· ·
LeetCode Easy Array String Simulation
Wei Yi Chung
Author
Wei Yi Chung
Working at the contributing of open source, distributed systems, and data engineering.
Table of Contents

Meta Data
#

Difficulty: easy First Attempt: 2026-02-14

  • Submissions: Accepted (first try)

Approach
#

For each word compute its total weight w and r = w % 26. Reverse alphabetical order is 0 -> 'z', 1 -> 'y', …, so the letter is chr(ord('z') - r) (Array Template 5).

My Solution
#

class Solution:
    def mapWordWeights(self, words: List[str], weights: List[int]) -> str:
        return "".join(
            chr(ord("z") - sum(weights[ord(c) - ord("a")] for c in w) % 26)
            for w in words
        )

Complexity
#

Time O(total characters), space O(number of words).

Mistakes to Avoid
#

  • The mapping is reversed: 0 maps to z, not a.

Interview Explanation
#

For each word I sum the letter weights mod 26 and subtract the remainder from ord('z') for the reversed letter, then join. Time O(total characters).

Related

LeetCode 3379: Transformed Array
·1 min
LeetCode Easy Array Simulation
LeetCode 3379 note: moving nums[i] steps right or left is nums[(i + nums[i]) % n]; Python’s % returns a non-negative result for negatives too
LeetCode 3813: Vowel-Consonant Score
·1 min
LeetCode Easy String Simulation
LeetCode 3813 note: count letters only, split into vowels and consonants; the score is 0 with no consonants, otherwise integer division
LeetCode 3701: Compute Alternating Sum
·1 min
LeetCode Easy Array Simulation
LeetCode 3701 note: add even indices and subtract odd ones; with slices, sum(nums[::2]) - sum(nums[1::2])
LeetCode 3688: Bitwise OR of Even Numbers in an Array
·1 min
LeetCode Easy Bit-Manipulation Array Simulation
LeetCode 3688 note: OR only the even numbers; the starting value 0 is also the answer when there are none
LeetCode 1920: Build Array from Permutation
·1 min
LeetCode Easy Array Simulation
LeetCode 1920 note: follow the definition ans[i] = nums[nums[i]]; for O(1) extra space, stack the new value times n on top of the old one
LeetCode 3069: Distribute Elements Into Two Arrays I
·1 min
LeetCode Easy Array Two-Pointers Simulation
LeetCode 3069 note: simulate the rule: the first two go to separate arrays, then each element joins the array whose last element is larger