Find four elements a , b , c and d in an array such that a + b = c + d | function to find a , b , c , d such that ( a + b ) = ( c + d ) ; Create an empty hashmap to store mapping from sum to pair indexes ; Traverse through all possible pairs of arr [ ] ; Sum already present in hash ; driver program
def find_pair_of_sum ( arr : list , n : int ) : NEW_LINE INDENT map = { } NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT sum = arr [ i ] + arr [ j ] NEW_LINE if sum in map : NEW_LINE INDENT print ( f " { map [ sum ] } ▁ and ▁ ( { arr [ i ] } , ▁ { arr [ j ] } ) " ) NEW_LINE return NEW_LINE DEDENT else : NEW_LINE INDENT map [ sum ] = ( arr [ i ] , arr [ j ] ) NEW_LINE DEDENT DEDENT DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT arr = [ 3 , 4 , 7 , 1 , 2 , 9 , 8 ] NEW_LINE n = len ( arr ) NEW_LINE find_pair_of_sum ( arr , n ) NEW_LINE DEDENT