text: Choose X elements from A [ ] and Y elements from B [ ] which satisfy the given condition | Function to that returns true if it possible to choose the elements ; If elements can 't be chosen ; Sort both the arrays ; If xth smallest element of A is smaller than the yth greatest element of B ; Driver code
code: function isPossible ( A , B , n , m , x , y ) { if ( x > n y > m ) return false ; A . sort ( ) ; B . sort ( ) ; if ( A [ x - 1 ] < B [ m - y ] ) return true ; else return false ; } var A = [ 1 , 1 , 1 , 1 , 1 ] ; var B = [ 2 , 2 ] ; var n = A . length ; var m = B . length ; ; var x = 3 , y = 1 ; if ( isPossible ( A , B , n , m , x , y ) ) document . write ( " " ) ; else document . write ( " " ) ;