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
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 7ms, memory 17.4MB, accepted 2025-12-30.
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