values of distinct integers sorted in increasing order. Find the smallest index i (0-based) with values[i] == i. If there is no such index, return -1.
A full O(n) scan is easy; try to find the answer faster.values=[-4, -1, 2, 5, 9] → 2
values[2] = 2, the first and only such index.
values=[-3, 1, 2, 3] → 1
Indices 1, 2 and 3 all match; the smallest one is 1.
values=[1, 3, 6] → -1
No value equals its own index.
values are distinct and strictly increasingvalues=[-4, -1, 2, 5, 9]
2
Run checks the first 3 tests in your browser. Submit checks all 118 tests on the server, hidden ones included.