human
Give me a code to maximum Count of pairs having equal Sum based on the given conditions and the other steps required given the following:
Maximum Count of pairs having equal Sum based on the given conditions | Function to find the maximum count of pairs having equal sum.
Size of the array.
Iterate through evey sum of pairs possible from the given array.
Count of pairs with given sum.
Check for a possible pair.
Update count of possible pair.
Update the answer by taking the pair which is maximum for every possible sum.
Return the max possible pair.
Function to return the count of pairs.
Size of the array.
Stores the frequencies.
Count the frequency.
Driver Code"
Solution in Python:
assistant
#Here is code to maximum Count of pairs having equal Sum based on the given conditions and the other steps required.
 def maxCount ( freq , maxi , mini ) :
	n = len ( freq ) - 1
	ans = 0
	sum = 2 * mini
	while sum <= 2 * maxi :
		possiblePair = 0
		for firElement in range ( 1 , ( sum + 1 ) // 2 ) :
			if ( sum - firElement <= maxi ) :
				possiblePair += min ( freq [ firElement ] , freq [ sum - firElement ] )
		sum += 1
		if ( sum % 2 == 0 ) :
			possiblePair += freq [ sum // 2 ] // 2
		ans = max ( ans , possiblePair )
	return ans
def countofPairs ( a ) :
	n = len ( a )
	freq = [ 0 ] * ( n + 1 )
	maxi = - 1
	mini = n + 1
	for i in range ( len ( a ) ) :
		maxi = max ( maxi , a [ i ] )
		mini = min ( mini , a [ i ] )
	for i in range ( n ) :
		freq [ a [ i ] ] += 1
	return maxCount ( freq , maxi , mini )
if __name__ == " _ _ main _ _ " :
	a = [ 1 , 2 , 4 , 3 , 3 , 5 , 6 ]
	print ( countofPairs ( a ) )