Description
Solutions
Submission
Fruit Crush 🍅
🔥 FULLTIME
Amazon recently launched a new game, Fruit Crush! In this game, you are allowed to choose two dissimilar fruits and crush them. Each type of fruit is represented as an integer in an array. Formally you can choose any two unequal integers in the array and delete them.
Given an array fruits
of size n
, return the minimum
possible number of fruits left after the given operation is performed any number of times.
Function Description
Complete the function getMinimumFruits
in the editor.
getMinimumFruits
has the following parameter(s):
int fruits[n]
: array of n fruitsReturns
int
: the minimum possible count of fruits leftExample 1:
Input: fruits = [3, 3, 1, 1, 2]
Output: 1
Explanation:Fruit 1 (banana) and 2 (pineapple) can be crushed first, followed by numbers 1(banana) and 3 (orange). Only 3 (orange) remains in the array, hence the answer is 1.
Example 2:
Input: fruits = [1, 2, 5, 6]
Output: 0
Explanation:Fruit 1 and 2 can be taken and fruit 5 and 6 can be taken. Hence no numbers are left.
Constraints:
1 <= n <= 105
1 <= fruits[i] <= 109
Related Problems
Testcase
Result
Case 1
input:
output: