Problem · Math
Let's Play Crush Fruit Together :)
Learn this problemProblem statement
Amazon launched a game called Fruit Crush. You are given an array fruitsArray of length n, where each integer represents a type of fruit.
In one operation, choose any two fruits with different types and remove both of them from the array.
You may perform the operation any number of times while possible. Return the minimum possible number of fruits left after all operations.
Function
getMinimumFruits(fruitsArray: int[]) → intExamples
Example 1
fruitsArray = [3, 3, 1, 1, 2]return = 1
We can first crush fruit type 1 (e.g., banana) with fruit type 2 (e.g., pineapple).
Next, we crush the remaining fruit type 1 (banana) with one fruit type 3 (orange).
Now, only one fruit type 3 (orange) remains in the array.
Since there are no distinct fruit types left to crush, the minimum number of remaining fruits is 1.
Example 2
fruitsArray = [1, 2, 5, 6]return = 0We can first crush fruit type 1 with fruit type 2.
Next, we can crush fruit type 5 with fruit type 6.
Since all fruit types have been successfully removed through crushing, the final number of fruits left is 0.
Constraints
1 <= n <= 1051 <= fruitsArray[i] <= 109
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026