Skip to main content

1338 - Reduce Array Size to The Half

Details

KeyValue
Linkhttps://leetcode.com/problems/reduce-array-size-to-the-half/
LanguagePython 3
Runtime994 ms, faster than 45.87% of Python3 online submissions for Reduce Array Size to The Half
Memory Usage35.7 MB, less than 44.35% of Python3 online submissions for Reduce Array Size to The Half
DatastructuresList[int]
AlgorithmsMost Common + Iteration
ComplexityTime: O(NlogN) Memory: O(N)

Procedure

  1. ...

Code

class Solution:
def minSetSize(self, arr: List[int]) -> int:
count = 0
most_common_integers = Counter(arr).most_common()

for i in range(len(most_common_integers)):
count += most_common_integers[i][1]
if count >= len(arr) // 2: return i + 1