FunctionRacerProblemsRace

Kth Largest Element

BeginnerSorting and searchingPython, JavaScript, TypeScript, Java, C++

Return the k-th largest item of nums when the items are sorted from biggest to smallest. Duplicates count separately: in [5, 5, 3] the 2nd largest is 5.

Example 1

nums [3,2,1,5,6,4]
k 2
returns 5

Sorted high to low: 6, 5, 4, ... so the 2nd is 5.

Example 2

nums [3,2,3,1,2,4,5,5,6]
k 4
returns 4

6, 5, 5, 4: the 4th is 4.

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 Sorting and searching problems