FunctionRacerProblemsRace

Only the Best Count

BeginnerGreedyPython, JavaScript, TypeScript, Java, C++

A quiz league keeps only your best results. scores lists every score you have made so far, and only the k highest of them count. Equal scores are separate results, so the same value can count more than once.

Return the total of the scores that count. If you have fewer than k scores, all of them count.

Example 1

scores [70,95,80,60]
k 2
returns 175

The two highest scores are 95 and 80, and 95 + 80 = 175.

Example 2

scores [50,50,50]
k 2
returns 100

Two of the three equal scores count: 50 + 50 = 100.

Example 3

scores [40,90]
k 5
returns 130

There are only two scores, so both count: 40 + 90 = 130.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Greedy problems