human
Find frequency of each element in a limited range array in less than O ( n ) time | python program to count number of occurrences of each element in the array in O ( n ) time and O ( 1 ) space.
check if the current element is equal to previous element ..
reset the frequency.
print the last element and its frequency ;"
How can the above be solved in Python?
 What is a code to find frequency of each element in a limited range array in less than O ( n ) time and the other steps required?
assistant
#Here is code to find frequency of each element in a limited range array in less than O ( n ) time and the other steps required.
 def findFrequencies ( ele , n ) :
	freq = 1
	idx = 1
	element = ele [ 0 ]
	while ( idx < n ) :
		if ( ele [ idx - 1 ] == ele [ idx ] ) :
			freq += 1
			idx += 1
		else :
			print ( element , " ▁ " , freq ) ;
			element = ele [ idx ]
			idx += 1
			freq = 1
	print ( element , " ▁ " , freq ) ;
/ * Driver code * /
print ( " - - - frequencies ▁ in ▁ a ▁ sorted ▁ array - - - - " ) ;
arr = [ 10 , 20 , 30 , 30 , 30 , 40 , 50 , 50 , 50 , 50 , 70 ] ;
n = len ( arr )
findFrequencies ( arr , n )