array and hashmap November 9, 2022

Distribute candies

Time O(n) Space O(n) Open original problem

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)