Distribute Candies Problem

Distribute Candies Problem — ExecCode Easy DSA Practice

Solve the Distribute Candies problem on ExecCode. Free online easy DSA practice in Arrays - Logic Building. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Description You are given the integer array candyType of length n, return the maximum number of different types of candies she can eat if she only eats n / 2 of them. Your task is to alice has n candies, where the i^th candy is of type candyType[i]. Alice noticed that she started to gain weight, so she visited a doctor. The doctor advised Alice to only eat n / 2 of the candies she has (n is always even). Alice likes her candies very much, and she wants to eat the maximum number of different types of candies while still following the doctor's advice. Return the required answer exactly as shown in the examples.

Examples

Input {"candyType": [1, 1, 2, 2, 3, 3]}; Output 3. Input {"candyType": [1, 1, 2, 3]}; Output 2

Constraints

n == candyType.length 2 <= n <= 10^4 n is even. -10^5 <= candyType[i] <= 10^5

Practice Distribute Candies free on ExecCode. Browse DSA problems, topic map, and placement guides.