human
Can you provide a code to print all array elements appearing more than N / K times and the other steps required given the following:
Print all array elements appearing more than N / K times | Function to + find the upper_bound of an array element.
Stores minimum index in which K lies.
Stores maximum index in which K lies.
Calculate the upper bound of K.
Stores mid element of l and r.
If arr [ mid ] is less than or equal to K.
Right subarray.
Left subarray.
Function to prall array elements whose frequency is greater than N / K.
Sort the array arr.
Stores index of an array element.
Traverse the array.
Stores upper bound of arr [ i ].
If frequency of arr [ i ] is greater than N / 4.
Update i.
Driver Code.
Given array arr.
Size of array.
Function Call"
How can the above be solved in Python?
assistant
#Here is code to print all array elements appearing more than N / K times and the other steps required.
 def upperBound ( arr , N , K ) :
	l = 0 ;
	r = N ;
	while ( l < r ) :
		mid = ( l + r ) // 2 ;
		if ( arr [ mid ] <= K ) :
			l = mid + 1 ;
		else :
			r = mid ;
	return l ;
def NDivKWithFreq ( arr , N , K ) :
	arr . sort ( ) ;
	i = 0 ;
	while ( i < N ) :
		X = upperBound ( arr , N , arr [ i ] ) ;
		if ( ( X - i ) > N // 4 ) :
			print ( arr [ i ] , end = " " ) ;
		i = X ;
if __name__ == ' _ _ main _ _ ' :
	arr = [ 1 , 2 , 2 , 6 , 6 , 6 , 6 , 7 , 10 ] ;
	N = len ( arr ) ;
	K = 4 ;
	NDivKWithFreq ( arr , N , K ) ;