values. List all **distinct** values of the array in descending order, writing equal numbers only once.
Return the third number in that list. If there are fewer than three distinct values, return the largest value of the array instead.values=[7, 10, 7, 4, 10, 1] → 4
The distinct values in descending order are 10, 7, 4, 1. The third one is 4; the repeated 10 and 7 count once.
values=[5, 5, 2] → 5
There are only two distinct values (5 and 2), so there is no third one and the largest, 5, is returned.
values=[-3, 0, -8, 0] → -8
The distinct values are 0, -3, -8. The third largest is -8.
values.length ≤ 10⁴values[i] ≤ 2³¹ − 1values=[7, 10, 7, 4, 10, 1]
4
Run checks the first 3 tests in your browser. Submit checks all 130 tests on the server, hidden ones included.