human
Find frequency of each element in a limited range array in less than O ( n ) time | It prints number of occurrences of each element in the array ..
HashMap to store frequencies.
traverse the array.
update the frequency.
traverse the hashmap.
Driver function"
Solution in Python:
 ... Write me 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 findFrequency ( arr , n ) :
	mp = { }
	for i in range ( n ) :
		if arr [ i ] not in mp :
			mp [ arr [ i ] ] = 0
		mp [ arr [ i ] ] += 1
	for i in mp :
		print ( " Element " , i , " occurs " , mp [ i ] , " times " )
arr = [ 1 , 1 , 1 , 2 , 3 , 3 , 5 , 5 , 8 , 8 , 8 , 9 , 9 , 10 ]
n = len ( arr )
findFrequency ( arr , n )