Online Python Compiler

def solve(nums, k): dictionary={} for num in nums: if num not in dictionary: dictionary[num]=1 else: dictionary[num]+=1 count=len(dictionary) for frequency in sorted(dictionary.values()): k-=frequency if(k<0): return count else: count-=1 return count nums = [5,4,2,2,4,4,3] k = 3 print(solve(nums, k))