I got an error in the following function which says that 'NoneType' object is not iterable
.
The print(max())
function works just fine when I put it outside the loop so why doesn't it work here?
def minSetSize(self, arr: List[int]) -> int:
target=len(arr)/2
sum=0
res=[]
hash={x:arr.count(x) for x in arr}
freq=list(hash.values())
while (sum<target):
sum+=max(freq) #error thrown here
res.append(max(freq))
freq=freq.remove(max(freq))
return len(res)