human
Write me a code to largest element in the array that is repeated exactly k times and the other steps required given the following:
Largest element in the array that is repeated exactly k times | Function that finds the largest element which is repeated ' k ' times.
sort the array.
if the value of ' k ' is 1 and the largest appears only once in the array.
counter to count the repeated elements.
check if the element at index ' i ' is equal to the element at index ' i + 1' then increase the count.
else set the count to 1 to start counting the frequency of the new number.
if the count is equal to k and the previous element is not equal to this element.
if there is no such element.
Driver code.
find the largest element that is repeated K times"
Solution in Python:
assistant
#Here is code to largest element in the array that is repeated exactly k times and the other steps required.
 def solve ( arr , n , k ) :
	arr . sort ( )
	if ( k == 1 and arr [ n - 2 ] != arr [ n - 1 ] ) :
		print ( arr [ n - 1 ] )
		return
	count = 1
	for i in range ( n - 2 , - 1 , - 1 ) :
		if ( arr [ i ] == arr [ i + 1 ] ) :
			count += 1
		else :
			count = 1
		if ( count == k and ( i == 0 or ( arr [ i - 1 ] != arr [ i ] ) ) ) :
			print ( arr [ i ] )
			return
	print ( " No ▁ such ▁ element " )
if __name__ == " _ _ main _ _ " :
	arr = [ 1 , 1 , 2 , 3 , 3 , 4 , 5 , 5 , 6 , 6 , 6 ]
	k = 2
	n = len ( arr )
	solve ( arr , n , k )