```
public int distributeCandies(int[] candies) {
Set<Integer> set = new HashSet<>();
for(Integer candie : candies) {
set.add(candie);
if(set.size() == candies.length/2) return set.size();
}
return Math.min(set.size(), candies.length/2);
}
```