values of distinct positive integers. Find the leftmost number that is neither the smallest nor the largest value in the array.
If there is no such number, return -1.
No sorting is needed: a linear pass is enough.values=[8, 3, 5, 10] → 8
The minimum is 3 and the maximum is 10. Reading left to right, 8 comes first and is neither.
values=[4, 9] → -1
Both numbers are extremes, so there is nothing to return.
values=[2, 6, 1, 7] → 2
The 2 is not the minimum (there is a 1) and not the maximum, so it is the first fit.
values are distinctvalues=[8, 3, 5, 10]
8
Run checks the first 3 tests in your browser. Submit checks all 89 tests on the server, hidden ones included.