Check if X and Y elements can be selected from two arrays respectively such that the maximum in X is less than the minimum in Y | Function to check if it is possible to choose X and Y elements from a and b such that maximum element among X element is less than minimum element among Y elements ; Check if there are atleast X elements in arr1 and atleast Y elements in arr2 ; Sort arrays in ascending order ; Check if ( X - 1 ) - th element in arr1 is less than from M - Yth element in arr2 ; Return false ; Driver Code ; Function Call
function check ( a , b , Na , Nb , k , m ) { if ( Na < k Nb < m ) return " " ; a . sort ( ) ; b . sort ( ) ; if ( a [ k - 1 ] < b [ Nb - m ] ) { return " " ; } return " " ; } var arr1 = [ 1 , 2 , 3 ] ; var arr2 = [ 3 , 4 , 5 ] ; var N = arr1 . length ; var M = arr2 . length ; var X = 2 , Y = 1 ; document . write ( check ( arr1 , arr2 , N , M , X , Y ) ) ;