**Set - O(N) time, O(N) space**

We can use a set to count all unique kinds of candies, but even all candies are unique, the sister cannot get more than half.

(Even though in reality my GF would always get more than half.)

```
class Solution {
public:
int distributeCandies(vector<int>& candies) {
unordered_set<int> kinds;
for (int kind : candies) {
kinds.insert(kind);
}
return min(kinds.size(), candies.size() / 2);
}
};
```

Using range constructor as @i_square suggested:

```
class Solution {
public:
int distributeCandies(vector<int>& candies) {
return min(unordered_set<int>(candies.begin(), candies.end()).size(), candies.size() / 2);
}
};
```

**Sort - O(N logN) time, O(1) space**

Or we can sort the candies by kinds, count kind if different than the prevous:

```
class Solution {
public:
int distributeCandies(vector<int>& candies) {
size_t kinds = 0;
sort(candies.begin(), candies.end());
for (int i = 0; i < candies.size(); i++) {
kinds += i == 0 || candies[i] != candies[i - 1];
}
return min(kinds, candies.size() / 2);
}
};
```

The counter can start from 1 since there is no test case for empty input:

```
class Solution {
public:
int distributeCandies(vector<int>& candies) {
size_t kinds = 1;
sort(candies.begin(), candies.end());
for (int i = 0; i < candies.size(); i++) {
kinds += candies[i] != candies[i - 1];
}
return min(kinds, candies.size() / 2);
}
};
```