The k-th from the wrong end
transcript
A leaderboard asks for the k-th highest score. You sort, and take position k minus one. The answer is wrong. The code looks fine, and the sort is correct.
Sorted low to high, the scores are one, two, three. Position zero holds one, the lowest. The highest score is at the end. It is the direction that is wrong, not the sort.
Sort low to high, and k equal to one returns the lowest. Sort high to low instead. Then k equal to one returns three, the highest. One word in the statement decides the direction.
The k-th fastest is the k-th smallest. The k-th highest is the k-th largest. Test with k equal to one on three different values. Say the direction aloud before you code.
Sorting a hundred thousand values costs about one point seven million comparisons. A heap of size k can do better. A three-way partition can too. But first, get the direction right.
Highest means largest. Test with k equal to one. Full breakdown in the lecture.