values. For each element values[i], look at the elements to its right and list, in order, those strictly greater than values[i]. The second one in that list is the answer for position i. If there are fewer than two of them, the answer is -1.
Return the array of answers, the same length as values.values=[3, 1, 5, 2, 7, 4] → [7, 2, -1, 4, -1, -1]
For 3 the larger values to its right are 5, then 7, so the answer is 7. For 1 they are 5, then 2: answer 2. 5 has only one larger value after it (7), so -1. For 2 they are 7, then 4: answer 4. Both 7 and 4 get -1.
values=[6, 6, 6] → [-1, -1, -1]
Equal values do not count as larger, so every answer is -1.
len(values) ≤ 10⁵values[i] ≤ 10⁹values=[3, 1, 5, 2, 7, 4]
[7, 2, -1, 4, -1, -1]
Run checks the first 3 tests in your browser. Submit checks all 226 tests on the server, hidden ones included.