Dsa
Arrays
Easy
Kth Largest Element
You are given an array of integers and an integer k. Write a program to find the k-th largest element in the array without sorting the entire array.
Input Format:
The first line contains two integers, n (the size of the array) and k (the k-th position).
The second line contains n space-separated integers, which are the elements of the array.
Output Format:
Output the k-th largest element.
Example:
Input:
5 2
3 2 1 5 4
Output:
4
In the example above, the 2nd largest element is 4.
Key concepts
arrayssortingselection
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now