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
< ? php function checkFittingArrays ( $ A , $ B , $ N ) { sort ( $ A ) ; sort ( $ B ) ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) if ( $ A [ $ i ] > $ B [ $ i ] ) return false ; return true ; } $ A = array ( 7 , 5 , 3 , 2 ) ; $ B = array ( 5 , 4 , 8 , 7 ) ; $ N = count ( $ A ) ; if ( checkFittingArrays ( $ A , $ B , $ N ) ) echo " YES " ; else echo " NO " ; ? >