Based on Bucket Sort:

```
public int distributeCandies(int[] candies) {
int[] b = new int[200001];
int nonEmptyBucketNo = 0;
for (int i : candies) if (b[i + 100000]++ == 0) nonEmptyBucketNo++;
return nonEmptyBucketNo <= candies.length / 2 ? nonEmptyBucketNo : candies.length / 2;
}
```