LeetCode Entry

3550. Smallest Index With Digit Sum Equal to Index

24.09.2026 easy 2026 kotlin rust

Position equal to number digits sum

3550. Smallest Index With Digit Sum Equal to Index easy substack youtube

https://dmitrysamoylenko.com/leetcode/

24.09.2026.webp

Join me on Telegram

https://t.me/leetcode_daily_unstoppable/1492

Problem TLDR

Position equal to number digits sum

Intuition

Iterate & check. Max position is 27 which is equal to the sum of 999

Approach

  • Kotlin: find, indexOfFirst, zip
  • Rust: find, zip

Complexity

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

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

Code

    fun smallestIndex(n: IntArray)=
    n.indices.find{it=="${n[it]}".sumOf{it-'0'}}?:-1
    pub fn smallest_index(n: Vec<i32>) -> i32 {
        (0..).zip(n).find(|(i,x)|*i==x/1000+x/100%10+x/10%10+x%10).map_or(-1,|p|p.0)
    }

Comments