LeetCode Entry

3838. Weighted Word Mapping

13.06.2026 easy 2026 kotlin rust

Convert words to chars by weighting their sums and reversing

3838. Weighted Word Mapping easy substack youtube

https://dmitrysamoylenko.com/leetcode/

13.06.2026.webp

Join me on Telegram

https://t.me/leetcode_daily_unstoppable/1389

Problem TLDR

Convert words to chars by weighting their sums and reversing

Intuition

brute-force

Approach

  • reverse by z-c

Complexity

  • Time complexity: \(O(nw)\)

  • Space complexity: \(O(n)\)

Code

    fun mapWordWeights(w: Array<String>, ws: IntArray) =
    w.joinToString(""){""+('z'-it.sumOf{ws[it-'a']}%26)}
    pub fn map_word_weights(w: Vec<String>, ws: Vec<i32>) -> String {
        w.iter().map(|s|(122-s.bytes().fold(0,|a,c|a+ws[(c-97)as usize])%26)as u8 as char).collect()
    }

Comments