A row of vending machine slots is numbered starting from 0. Each slot has a small display that always shows a single digit between 0 and 9. A technician defines a slot as self-calibrated when the slot's index, taken modulo 10, equals the digit currently shown on its display. Find the smallest index of a self-calibrated slot. If no slot is self-calibrated, report -1.
n, the number of slots.n space-separated integers nums[0..n-1], the digit shown on slot i.A single integer: the smallest index i such that i % 10 == nums[i], or -1 if no such index exists.
i.Example 1
Input
3 0 1 2
Expected
0
Explanation
At index 0, 0 % 10 = 0, which equals nums[0] = 0, so slot 0 is self-calibrated. Since it is the smallest index checked, the answer is 0.
Example 2
Input
4 4 3 2 1
Expected
2
Explanation
Index 0: 0 % 10 = 0 vs nums[0] = 4, no match. Index 1: 1 % 10 = 1 vs nums[1] = 3, no match. Index 2: 2 % 10 = 2 vs nums[2] = 2, a match. Since this is the first match found, the answer is 2.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →