JuniorArrayMath

Smallest Index With Digit Sum Equal to Index

You are given an integer array nums.

Return the smallest index i such that the sum of the digits of nums[i] is equal to i.

If no such index exists, return -1.

Example 1
Inputnums = [1,3,2]
Output2
For nums[2] = 2, the sum of digits is 2, which is equal to index i = 2, so the output is 2.
Example 2
Inputnums = [1,10,11]
Output1
Both indices 1 and 2 satisfy the condition, but index 1 is the smallest.

Constraints

  • 1 <= nums.length <= 100
  • 0 <= nums[i] <= 1000

Asked at 1 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate