AmazonOA #35
Fruit Crush (Get Min Fruits)
Estimated MediumJudge-ready
Each time, remove two fruits of different kinds; you may choose any positions and repeat this any number of times. Find the minimum number of fruits left at the end.
Input
The first line contains n (1..100000), and the second line contains n kind IDs (1..10⁹).
Output
Output a single integer, the answer.
Example 1
Input:
5
3 3 1 1 2
Output:
1
Example 2
Input:
4
1 1 1 2
Output:
2
Example 3
Input:
2
1 2
Output:
0
Example notes
Example 1: remove one 3 together with a 1, then the other 3 with another 1, leaving the 2, so 1 fruit remains. Example 2: the only 2 can remove just one 1, leaving two 1s. Example 3: the two kinds are removed together directly, leaving 0.
Editorial
Loading solution…