LeetCode solutions

3869. Smallest Index With Digit Sum Equal to Index

My accepted Python solution to LeetCode problem 3869, Smallest Index With Digit Sum Equal to Index, running in 7ms.

  • Difficulty: Easy
  • Python
  • Runtime 7ms
  • Memory 17.4MB

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 7ms, memory 17.4MB, accepted 2025-12-30.

python
class Solution:
    def smallestIndex(self, nums: List[int]) -> int:
        def digit_sum(n):
            return sum(int(d) for d in str(n))
        for i, num in enumerate(nums):
            if digit_sum(num) == i:
                return i
        return -1

Source