Find pairs in array whose sum does not exist in Array | Function to print all pairs with sum not present in the array ; Corner Case ; Stores the distinct array elements ; Generate all possible pairs ; Calculate sum of current pair ; Check if the sum exists in the HashSet or not ; Driver Code
def findPair ( arr , n ) : NEW_LINE INDENT if ( n < 2 ) : NEW_LINE INDENT print ( " - 1" ) NEW_LINE DEDENT hashMap = [ ] NEW_LINE for k in arr : NEW_LINE INDENT hashMap . append ( k ) NEW_LINE DEDENT for i in range ( n - 1 ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT sum = arr [ i ] + arr [ j ] NEW_LINE if sum not in hashMap : NEW_LINE INDENT print ( " ( " , arr [ i ] , " , ▁ " , arr [ j ] , " ) " ) NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 2 , 4 , 2 , 6 ] NEW_LINE n = len ( arr ) NEW_LINE findPair ( arr , n ) NEW_LINE DEDENT