Print all array elements appearing more than N / K times | Function to print all 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
function NDivKWithFreq ( arr , N , K ) { arr . sort ( ) ; for ( let i = 0 ; i < N ; ) { let cnt = 1 ; while ( ( i + 1 ) < N && arr [ i ] == arr [ i + 1 ] ) { cnt ++ ; i ++ ; } if ( cnt > ( N / K ) ) { document . write ( arr [ i ] + " " ) ; } i ++ ; } } let arr = [ 1 , 2 , 2 , 6 , 6 , 6 , 6 , 7 , 10 ] ; let N = arr . length ; let K = 4 ; NDivKWithFreq ( arr , N , K ) ;