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:
-1
💡 Note:
No index i satisfies i % 10 == nums[i]: 0≠4, 1≠3, 2≠2 is false, 3≠1
Example 3 — Double Digit Index
$
Input:
nums = [1,2,3,4,5,6,7,8,9,0,1,2,3]
›
Output:
10
💡 Note:
At index 10: 10 % 10 = 0 but nums[10] = 1, continue. At index 12: 12 % 10 = 2 but nums[12] = 3. Actually at index 10: 10 % 10 = 0 and nums[10] = 1, so no match until later.
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