Kth Largest Element
Mediumjavapythonccppjavascript
Given an unsorted array and an integer K, find the K-th largest element (1-indexed).
Input Format
The first line contains two integers N and K. The second line contains N space-separated integers.
Output Format
Print the K-th largest element.
Example 1
Input
6 2 3 2 1 5 6 4
Output
5
Explanation: The two largest values are 6 and 5, so the answer is 5.
- 1 <= K <= N <= 100000
- -1000000000 <= A[i] <= 1000000000