LeetCode Entry

3498. Reverse Degree of a String

20.09.2026 easy 2026 kotlin rust

Sum position times reversed letter

3498. Reverse Degree of a String easy substack youtube

https://dmitrysamoylenko.com/leetcode/

20.09.2026.webp

Join me on Telegram

https://t.me/leetcode_daily_unstoppable/1488

Problem TLDR

Sum position times reversed letter

Intuition

If we go from the tail, the scan would naturally calculates positions.

Approach

  • {-c or 123-c

Complexity

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

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

Code

    fun reverseDegree(s: String) =
    s.map{'{'-it}.reversed().scan(0,Int::plus).sum()
    pub fn reverse_degree(s: String) -> i32 {
        s.bytes().zip(1..).map(|(b, i)| i*(123-b as i32)).sum()
    }

Comments