values of distinct integers. In one move you may remove either the first or the last element of the array.
You need to remove both the smallest and the largest element. Return the minimum number of moves that achieves this.values=[6, 3, 9, -2, 4, 1, 5] → 4
The maximum 9 is at position 2 and the minimum -2 at position 3. The cheapest is to take 4 elements from the front.
values=[0, 8, 2, 4, 7, -1, 6] → 4
Take 2 from the front (reaching 8) and 2 from the back (reaching -1), 4 in total.
values=[13] → 1
The only element is both the minimum and the maximum.
values are distinctvalues=[6, 3, 9, -2, 4, 1, 5]
4
Run checks the first 3 tests in your browser. Submit checks all 103 tests on the server, hidden ones included.