human
Give me a code to find the frequency of each element in a sorted array and the other steps required given the following:
Find the frequency of each element in a sorted array | Function to print the frequency of each element of the sorted array.
Stores the frequency of an element.
Traverse the array arr [ ].
If the current element is equal to the previous element.
Increment the freq by 1.
Otherwise ,.
Update freq.
Print the frequency of the last element.
Driver Code.
Given Input.
Function Call"
Solution in Python:
assistant
#Here is code to find the frequency of each element in a sorted array and the other steps required.
 def printFreq ( arr , N ) :
	freq = 1
	for i in range ( 1 , N , 1 ) :
		if ( arr [ i ] == arr [ i - 1 ] ) :
			freq += 1
		else :
			print ( " Frequency ▁ of " , arr [ i - 1 ] , " is : " , freq )
			freq = 1
	print ( " Frequency ▁ of " , arr [ N - 1 ] , " is : " , freq )
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 1 , 1 , 2 , 3 , 3 , 5 , 5 , 8 , 8 , 8 , 9 , 9 , 10 ]
	N = len ( arr )
	printFreq ( arr , N )