Kth Largest Element solution using priority queue


#1

vector Solution::solve(vector &A, int B) {
priority_queue q;
for(int i=0;i<A.size();i++)
{
q.push(A[i]);
}
B=B;
vector ans;
while(B-- && !q.empty())
{
ans.push_back(q.top());
q.pop();
}

return ans;

}