human
Can you provide a code to find the repeating element in an Array of size N consisting of first M natural numbers and the other steps required given the following:
Find the repeating element in an Array of size N consisting of first M natural numbers | Function to calculate the repeating character in a given permutation.
variables to store maximum element and sum of the array respectively ..
calculate sum of array.
calculate maximum element in the array.
calculating sum of permutation.
calculate required answer.
Driver code.
Input.
Function call"
Solution in Python:
assistant
#Here is code to find the repeating element in an Array of size N consisting of first M natural numbers and the other steps required.
 def repeatingElement ( arr , N ) :
	M = 0
	sum = 0
	for i in range ( N ) :
		sum += arr [ i ]
		M = max ( M , arr [ i ] )
	sum1 = M * ( M + 1 ) // 2
	ans = ( sum - sum1 ) // ( N - M )
	return ans
if __name__ == ' _ _ main _ _ ' :
	arr = [ 2 , 6 , 4 , 3 , 1 , 5 , 2 ]
	N = len ( arr )
	print ( repeatingElement ( arr , N ) )