Permute two arrays such that sum of every pair is greater or equal to K | Check whether any permutation exists which satisfy the condition . ; Sort the array a [ ] in decreasing order . ; Sort the array b [ ] in increasing order . ; Checking condition on each index . ; Driven Program
function isPossible ( a , b , n , k ) { a . sort ( function ( a , b ) { return a - b } ) ; b . reverse ( ) ; for ( let i = 0 ; i < n ; i ++ ) if ( a [ i ] + b [ i ] < k ) return false ; return true ; } let a = [ 2 , 1 , 3 ] ; let b = [ 7 , 8 , 9 ] ; let k = 10 ; let n = a . length ; if ( isPossible ( a , b , n , k ) ) document . write ( " " ) ; else document . write ( " " ) ;