Divide array into two arrays which does not contain any pair with sum K | Function to split the given array into two separate arrays satisfying given condition ; Stores resultant arrays ; Traverse the array ; If a [ i ] is smaller than or equal to k / 2 ; Print first array ; Print second array ; Given K ; Given array ; Given size
function splitArray ( a , n , k ) { let first = [ ] ; let second = [ ] ; for ( let i = 0 ; i < n ; i ++ ) { if ( a [ i ] <= parseInt ( k / 2 ) ) first . push ( a [ i ] ) ; else second . push ( a [ i ] ) ; } for ( let i = 0 ; i < first . length ; i ++ ) { document . write ( first [ i ] + " " ) ; } document . write ( " " ) ; for ( let i = 0 ; i < second . length ; i ++ ) { document . write ( second [ i ] + " " ) ; } } let k = 5 ; let a = [ 0 , 1 , 3 , 2 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] ; let n = a . length ; splitArray ( a , n , k ) ;