Easy sol in JAVA -->


#1

public class Solution {
public int[] solve(int[] A, int B) {

    int[] result = new int[B] ;
    
    PriorityQueue<Integer> minH  = new PriorityQueue<>( (a,b) -> a - b ) ;
    
    for( int i = 0 ; i < A.length ; i++ )
    {
        minH.add( A[i] ) ;
        if( minH.size() > B ) 
        {
            minH.remove() ;
        }
    }
    
    while( B-- > 0)
    {
        result[B] =  minH.element()  ;
        minH.remove() ;
    }
    
    return result ;
}

}