Print all array elements appearing more than N / K times | Function to prall array elements whose frequency is greater than N / K ; Sort the array , arr [ ] ; Traverse the array ; Stores frequency of arr [ i ] ; Traverse array elements which is equal to arr [ i ] ; Update cnt ; Update i ; If frequency of arr [ i ] is greater than ( N / K ) ; Driver Code
def NDivKWithFreq ( arr , N , K ) : NEW_LINE INDENT arr = sorted ( arr ) NEW_LINE i = 0 NEW_LINE while i < N : NEW_LINE INDENT cnt = 1 NEW_LINE while ( ( i + 1 ) < N and arr [ i ] == arr [ i + 1 ] ) : NEW_LINE INDENT cnt += 1 NEW_LINE i += 1 NEW_LINE DEDENT if ( cnt > ( N // K ) ) : NEW_LINE INDENT print ( arr [ i ] , end = " ▁ " ) NEW_LINE DEDENT i += 1 NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 1 , 2 , 2 , 6 , 6 , 6 , 6 , 7 , 10 ] NEW_LINE N = len ( arr ) NEW_LINE K = 4 NEW_LINE NDivKWithFreq ( arr , N , K ) NEW_LINE DEDENT