Smallest Index With Equal Value - Problem
Given a 0-indexed integer array nums, return the smallest index i of nums such that i mod 10 == nums[i], or -1 if such index does not exist.
x mod y denotes the remainder when x is divided by y.
Input & Output
Example 1 — Found Match
$
Input:
nums = [0,1,2,3,4,5,6,7,8,9]
›
Output:
0
💡 Note:
At index 0: 0 % 10 = 0 and nums[0] = 0, so return 0
Example 2 — Later Match
$
Input:
nums = [4,3,2,1]
›
Output:
2
💡 Note:
At index 2: 2 % 10 = 2 and nums[2] = 2, so return 2
Example 3 — Double Digit Index
$
Input:
nums = [1,2,3,4,5,6,7,8,9,0,1,2,3]
›
Output:
-1
💡 Note:
No index i satisfies i % 10 == nums[i]. Checking all indices: 0≠1, 1≠2, 2≠3, etc. No match found.
Constraints
- 1 ≤ nums.length ≤ 100
- 0 ≤ nums[i] ≤ 9
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code