Ctrl K

Index Matching Its Digit

Easy
You get an array digits where every element is a digit from 0 to 9. Find the smallest index i (0-based) whose last digit equals the element stored there, that is, i % 10 == digits[i]. If there is no such index, return -1.
Example 1
digits=[5, 5, 5, 5, 5, 5] → 5

Only index 5 has a last digit equal to its value.

Example 2
digits=[9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 0, 1] → 10

Nothing matches up to index 9, but index 10 ends in 0, the same as its value.

Example 3
digits=[1, 0] → -1

No index qualifies.

Constraints
  • 1 ≤ len(digits) ≤ 100
  • 0 ≤ digits[i] ≤ 9
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPair With a Target Sum EasySqueeze Repeats Out of a Sorted Array EasyDrop the Unwanted Value EasySlot on a Sorted Shelf EasyAdd One to a Digit Array Easy
loading Python…
Input
digits=[5, 5, 5, 5, 5, 5]
Expected
5

Run checks the first 3 tests in your browser. Submit checks all 89 tests on the server, hidden ones included.