human
Find all array elements occurring more than âŒŠN / 3 âŒ ‹ times | ''Function to find Majority element in an array.
'' if this element is previously seen,  increment count1..
'' if this element is previously seen,  increment count2..
'' if current element is different from  both the previously seen variables, decrement both the counts..
 ;"
Solution in Python:
 Can you provide a code to find all array elements occurring more than âŒŠN / 3 âŒ ‹ times and the other steps required?
assistant
#Here is code to find all array elements occurring more than âŒŠN / 3 âŒ ‹ times and the other steps required.
 def findMajority ( arr , n ) :
	count1 = 0
count2 = 0
= first = 2147483647
	second = 2147483647
	flag = 0
for i in range ( n ) :
	if first == arr [ i ] :
	count1 += 1
	elif second == arr [ i ] :
	count2 += 1
	elif count1 == 0 :
	count1 += 1
first = arr [ i ]
	elif count2 == 0 :
	count2 += 1
	second = arr [ i ]
else :
	count1 -= 1
	count2 -= 1
	count1 = 0
	count2 = 0
' gain traverse the array and find the
	actual counts . ''' 
 ▁ for ▁ i ▁ in ▁ range ( n ) : 
 ▁ if ▁ arr [ i ] ▁ = = ▁ first : 
 ▁ count1 ▁ + = ▁ 1 
 ▁ elif ▁ arr [ i ] ▁ = = ▁ second : 
 count2 ▁ + = ▁ 1 
 ▁ if ▁ count1 ▁ > ▁ int ( n ▁ / ▁ 3 ) : 
 ▁ print ( first , ▁ end ▁ = ▁ " ▁ " ) 
 ▁ flag ▁ = ▁ 1 
 ▁ if ▁ count2 ▁ > ▁ int ( n ▁ / ▁ 3 ) : 
 print ( second , ▁ end ▁ = ▁ " ▁ " ) 
 ▁ flag ▁ = ▁ 1 
 ▁ if ▁ flag ▁ = = ▁ 0 : 
 ▁ print ( " No ▁ Majority ▁ Element " ) 
 ' Driver ▁ code ▁ '''
arr = [ 2 , 2 , 3 , 1 , 3 , 2 , 1 , 1 ]
n = len ( arr )
findMajority ( arr , n )