Count pairs from an array having equal sum and quotient | Function to find number of pairs with equal sum and quotient from a given array ; Store the count of pairs ; Stores frequencies ; Traverse the array ; If y is neither 1 or 0 ; Evaluate x ; Increment count by frequency of x ; Update map ; Prthe final count ; Driver Code ; Function Call
def countPairs ( a , n ) : NEW_LINE INDENT count = 0 NEW_LINE mp = { } NEW_LINE for i in range ( n ) : NEW_LINE INDENT y = a [ i ] NEW_LINE if ( y != 0 and y != 1 ) : NEW_LINE INDENT x = ( ( ( y * 1.0 ) // ( 1 - y ) ) * y ) NEW_LINE count += mp . get ( x , 0 ) NEW_LINE DEDENT mp [ y ] = mp . get ( y , 0 ) + 1 NEW_LINE DEDENT return count NEW_LINE DEDENT arr = [ - 4 , - 3 , 0 , 2 , 1 ] NEW_LINE N = len ( arr ) NEW_LINE print ( countPairs ( arr , N ) ) NEW_LINE