i<sup>th</sup> candy is of type
You want to distribute the candies equally between a sister and a brother so that each of them gets
n / 2 candies (
n is even). The sister loves to collect different types of candies, so you want to give her the maximum number of different types of candies.
Return the maximum number of different types of candies you can give to the sister.
Input: candies = [1,1,2,2,3,3] Output: 3 Explanation: There are three different kinds of candies (1, 2 and 3), and two candies for each kind. Optimal distribution: The sister has candies [1,2,3] and the brother has candies [1,2,3], too. The sister has three different kinds of candies.
Input: candies = [1,1,2,3] Output: 2 Explanation: For example, the sister has candies [2,3] and the brother has candies [1,1]. The sister has two different kinds of candies, the brother has only one kind of candies.
Input: candies = [1,1] Output: 1
Input: candies = [1,11] Output: 1
Input: candies = [2,2] Output: 1
n == candies.length
2 <= n <= 10<sup>4</sup>
-10<sup>5</sup> <= candies[i] <= 10<sup>5</sup>
The solution in Java code
Here we use a HashSet, add each of the candies, and then return the minimum size of either the set’s total size, or half of the overall candies amount.