scores, listed in the order they performed. Exactly count performers advance to the final, and their combined score must be as large as possible.
Return the finalists' scores in the order they performed.
If more performers share a score than there are spots left for it, the ones who performed later (higher indices) advance, so the answer is unique.scores=[4, -2, 9, 1, 7], count=3 → [4, 9, 7]
The three largest values are 4, 9 and 7. In their original order that is [4, 9, 7], with sum 20.
scores=[5, 8, 5, 5], count=2 → [8, 5]
We take 8 and one of the 5s. There are three 5s, and the rule says to take the rightmost one, so the answer is [8, 5], not [5, 8].
scores=[-3, -1, -4], count=1 → [-1]
All values are negative; the best one is -1.
scores=[4, -2, 9, 1, 7], count=3
[4, 9, 7]
Run checks the first 3 tests in your browser. Submit checks all 101 tests on the server, hidden ones included.