Tap here to switch tabs
Problem
Submissions

Problem: Distribute Candies

med
30 min
Try to solve the Distribute Candies problem.

Statement

Alice has n candies, where the candy at index i is of type candyType[i]. She is permitted to eat at most n/2n / 2 of her candies (n is always even).

Alice wants to maximize the number of distinct candy types she can eat while following this restriction.

Given the integer array candyType of length n, return the maximum number of unique candy types she can eat if she eats n/2n / 2 candies.

Constraints:

  • n == candyType.length

  • 2≤2 \leq n ≤104\leq 10^4

  • n is even.

  • −105≤-10^5 \leq candyType[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Distribute Candies

med
30 min
Try to solve the Distribute Candies problem.

Statement

Alice has n candies, where the candy at index i is of type candyType[i]. She is permitted to eat at most n/2n / 2 of her candies (n is always even).

Alice wants to maximize the number of distinct candy types she can eat while following this restriction.

Given the integer array candyType of length n, return the maximum number of unique candy types she can eat if she eats n/2n / 2 candies.

Constraints:

  • n == candyType.length

  • 2≤2 \leq n ≤104\leq 10^4

  • n is even.

  • −105≤-10^5 \leq candyType[i] ≤105\leq 10^5