human
Majority Element | Function to find Majority element in an array.
sentinels.
update maxCount if count of current element is greater.
if maxCount is greater than n / 2 return the corresponding element.
Driver code.
Function calling"
Solution in Python:
assistant
#Here is code to majority Element and the other steps required.
 def findMajority ( arr , n ) :
	maxCount = 0
	index = - 1
	for i in range ( n ) :
		count = 0
		for j in range ( n ) :
			if ( arr [ i ] == arr [ j ] ) :
				count += 1
		if ( count > maxCount ) :
			maxCount = count
			index = i
	if ( maxCount > n // 2 ) :
		print ( arr [ index ] )
	else :
		print ( " No ▁ Majority ▁ Element " )
if __name__ == " _ _ main _ _ " :
	arr = [ 1 , 1 , 2 , 1 , 3 , 5 , 1 ]
	n = len ( arr )
	findMajority ( arr , n )