Distribute candies
November 9, 2022
array-and-hashmapProblem URL: Distribute candies
We will use a set to keep track of the unique types of candies. We will then return the minimum of the length of the set and half the length of the candy array.
class Solution:
def distributeCandies(self, candyType: List[int]) -> int:
return min(len(set(candyType)), len(candyType)//2)
Time Complexity: O(n)
Space Complexity: O(n)