contains category wise problems(data structures, competitive) of popular platforms.
View the Project on GitHub mayankdutta/category-wise-problems
215. Kth Largest Element in an Array
heap
question.class Solution {
public int findKthLargest(int[] nums, int k) {
PriorityQueue<Integer> pq = new PriorityQueue<>(new Comparator<>() {
@Override
public int compare(Integer one, Integer two) {
return two.compareTo(one);
}
});
for (Integer i: nums) {
pq.add(i);
}
int ans = 0;
for (int i = 0; i < k; i ++) {
ans = pq.poll();
}
return ans;
}
}