Check whether an array can be fit into another array rearranging the elements in the array | Returns true if the array A can be fit into array B , otherwise false ; Sort both the arrays ; Iterate over the loop and check whether every array element of A is less than or equal to its corresponding array element of B ; Driver Code
function checkFittingArrays ( A , B , N ) { A . sort ( function ( a , b ) { return a - b ; } ) ; B . sort ( function ( a , b ) { return a - b ; } ) ; for ( let i = 0 ; i < N ; i ++ ) if ( A [ i ] > B [ i ] ) return false ; return true ; } let A = [ 7 , 5 , 3 , 2 ] ; let B = [ 5 , 4 , 8 , 7 ] ; let N = A . length ; if ( checkFittingArrays ( A , B , N ) ) document . write ( " " ) ; else document . write ( " " ) ;