human
Difference between sum of odd and even frequent elements in an Array | Function to find the sum of all even and odd frequent elements in an array.
Stores the frequency of array elements.
Traverse the array.
Update frequency of current element.
Stores sum of odd and even frequent elements.
Traverse the map.
If frequency is odd.
Add sum of all occurrences of current element to sum_odd.
If frequency is even.
Add sum of all occurrences of current element to sum_even.
Calculate difference between their sum.
Return diff.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to difference between sum of odd and even frequent elements in an Array and the other steps required.
 def findSum ( arr , N ) :
	mp = { }
	for i in range ( 0 , N ) :
		if arr [ i ] in mp :
			mp [ arr [ i ] ] += 1
		else :
			mp [ arr [ i ] ] = 1
	sum_odd , sum_even = 0 , 0
	for itr in mp :
		if ( mp [ itr ] % 2 != 0 ) :
			sum_odd += ( itr ) * ( mp [ itr ] )
		if ( mp [ itr ] % 2 == 0 ) :
			sum_even += ( itr ) * ( mp [ itr ] )
	diff = sum_even - sum_odd
	return diff
arr = [ 1 , 5 , 5 , 2 , 4 , 3 , 3 ]
N = len ( arr )
print ( findSum ( arr , N ) )