values, say the scores of each day of a trip in order. For every day you want to know the highest score still waiting ahead.
Replace each element with the largest of the elements **strictly to its right**. The last element has nothing to its right, so replace it with -1. Return the resulting array.values=[3, 9, 2, 7, 7] → [9, 7, 7, 7, -1]
To the right of 3 the max is 9, of 9 it is 7, of 2 it is 7, of the first 7 it is the second 7, and nothing follows the last one, hence -1.
values=[42] → [-1]
The only element is also the last one, so it becomes -1.
values.length ≤ 10⁵values[i] ≤ 10⁵values=[3, 9, 2, 7, 7]
[9, 7, 7, 7, -1]
Run checks the first 3 tests in your browser. Submit checks all 102 tests on the server, hidden ones included.