
from collections import defaultdict
def solution(k, tangerine):
#서로 다른 종류가 최소가 되도록.
# 1 3 2 5 4 5 2 3
# 1:1 2:2 3:2 4:1 5:2 sort by descreading reverse = True
# 2:2 3:2 5:2 + 1:1 4:1
answer = 0
currentSum = 0
tangerine.sort() # increa
tanDict = defaultdict(int)
for tan in tangerine:
tanDict[tan] += 1
sortedTanDictList = sorted(tanDict.items(), key=lambda x:x[1], reverse = True)
if sortedTanDictList[0][1] >= k:
return 1 #one kind thus return right away
# add up values and increament answer counter every key
else:
for kind in sortedTanDictList:
if currentSum < k:
currentSum += kind[1]
answer += 1
else:
break
return answer