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 ; Driver Code ; Given K ; Given array ; Given size
def splitArray ( a , n , k ) : NEW_LINE INDENT first = [ ] NEW_LINE second = [ ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( a [ i ] <= k // 2 ) : NEW_LINE INDENT first . append ( a [ i ] ) NEW_LINE DEDENT else : NEW_LINE INDENT second . append ( a [ i ] ) NEW_LINE DEDENT DEDENT for i in range ( len ( first ) ) : NEW_LINE INDENT print ( first [ i ] , end = " ▁ " ) NEW_LINE DEDENT print ( " " , ▁ end ▁ = ▁ " " ) NEW_LINE for i in range ( len ( second ) ) : NEW_LINE INDENT print ( second [ i ] , end = " ▁ " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT k = 5 NEW_LINE a = [ 0 , 1 , 3 , 2 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] NEW_LINE n = len ( a ) NEW_LINE splitArray ( a , n , k ) NEW_LINE DEDENT