Get Minimum Removals
Learn this problemProblem statement
Amazon's data analysts are currently working on an exciting new prototype that focuses on data pruning. In this challenge, you are presented with an array of integers named numbers, containing n elements, and an integer called allowedDistinct. The objective is to strategically remove as few elements as possible from the numbers array so that the remaining dataset contains no more than allowedDistinct unique values.
In other words, given the input array data and the parameter max_distinct, your challenge is to determine the minimum number of elements that must be removed so that the resulting array has at most max_distinct unique elements.
To accomplish this, you need to complete the function getMinRemovals with the following parameters:
int numbers[n]: The input array of integer data.int allowedDistinct: The maximum number of distinct elements allowed in the pruned array.The function should return an integer representing the minimum number of elements that must be removed to achieve an array with at most allowedDistinct unique elements.
Function
getMinRemovals(numbers: int[], alllowedDistinct: int) → intExamples
Example 1
numbers = [1, 2, 3, 2, 1]alllowedDistinct = 2return = 1
Constraints
1 ≤ n ≤ 10^51 ≤ numbers[i] ≤ 10^91 ≤ allowedDistinct ≤ 10^5More 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