Count of all possible pairs of array elements with same parity | Function to return the answer ; Generate all possible pairs ; Increment the count if both even or both odd ; Driver Code
def countPairs ( A , n ) : NEW_LINE INDENT count = 0 NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT if ( ( A [ i ] % 2 == 0 and A [ j ] % 2 == 0 ) or ( A [ i ] % 2 != 0 and A [ j ] % 2 != 0 ) ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT DEDENT DEDENT return count NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT A = [ 1 , 2 , 3 , 1 , 3 ] NEW_LINE n = len ( A ) NEW_LINE print ( countPairs ( A , n ) ) NEW_LINE DEDENT