Given an array of size n and a number k , find all elements that appear more than n / k times | Python3 implementation ; Function to find the number of array elements with frequency more than n / k times ; Calculating n / k ; Counting frequency of every element using Counter ; Traverse the map and print all the elements with occurrence more than n / k times ; Driver code
from collections import Counter NEW_LINE def printElements ( arr , n , k ) : NEW_LINE INDENT x = n // k NEW_LINE mp = Counter ( arr ) NEW_LINE for it in mp : NEW_LINE INDENT if mp [ it ] > x : NEW_LINE INDENT print ( it ) NEW_LINE DEDENT DEDENT DEDENT arr = [ 1 , 1 , 2 , 2 , 3 , 5 , 4 , 2 , 2 , 3 , 1 , 1 , 1 ] NEW_LINE n = len ( arr ) NEW_LINE k = 4 NEW_LINE printElements ( arr , n , k ) NEW_LINE