Ranked from the Top
Imagine a ranking of results where you need to know who is in the k-th place from the top. Write find_kth_largest to return the k-th largest element in nums. Count from the largest element, starting at 1. Duplicate numbers count as separate elements, like separate places in a ranking.
Примеры
Ввод
[3, 2, 1, 5, 6, 4], 2Вывод
5Ввод
[3, 2, 3, 1, 2, 4, 5, 5, 6], 4Вывод
4Ввод
[1], 1Вывод
1Нужно реализовать
def find_kth_largest(nums: list[int], k: int) -> int:
Теги
arraysortingbinary-search
Kirjaudu sisään nähdäksesi palautushistorian
Kirjaudu sisäänKirjaudu sisään käyttääksesi tekoälymentoria
Kirjaudu sisäänVisible tests
1
Input
[3,2,1,5,6,4], 2Expected
52
Input
[3,2,3,1,2,4,5,5,6], 4Expected
43
Input
[1], 1Expected
14
Input
[7,7,7], 2Expected
75
Input
[-1,-2,-3,-4], 1Expected
-16
Input
[3,2,1,5,6,4,3,2], 1Expected
6Focus radio
Paused · SomaFM · Fluid