Simple C++ solution, using MIN Heap


#1

vector Solution::solve(vector &A, int B) {
priority_queue<int,vector,greater>q;
vectorv;
for(int i=0; i<A.size(); i++)
{
q.push(A[i]);
if(q.size()>B)
{ q.pop();}
}
for(int i=0; i<B; i++)
{
v.push_back(q.top());
q.pop();
}
return v;
}