Find Kth Largest Element
Practice this coding question on Coding Gurukul.
Problem statement
A scoreboard stores unsorted scores and a rank k. Find the score in position k when scores are ordered from largest to smallest. Equal scores occupy separate positions; this is not a ranking of distinct values.
Input format
First line: n k. Second line: n scores.
Output format
Print the kth largest value.
Constraints
1 <= k <= n <= 100000; -1000000000 <= score <= 1000000000.
Sample input
6 3 8 2 8 -1 4 6
Sample output
6
Sign in to run or submit a solution in C++, Java or Python.