Problem · Sliding Window
Amazon Care Get Minimum Score
Learn this problemProblem statement
Given an array of integers and two specified numbers, find a subarray from the original array that contains both of these specified numbers, with the requirement that the subarray contains the minimum number of distinct numbers. Return the count of distinct numbers in this subarray.
If the two specified numbers are the same, simply return 1 if the array contains this number, otherwise return 0.
Function
findSubarrayWithMinimumDistinctIntegers(array: int[], series1: int, series2: int) → int
Complete the function findSubarrayWithMinimumDistinctIntegers in the editor.
findSubarrayWithMinimumDistinctIntegers has the following parameters:
- 1.
int[] array: an array of integers - 2.
int series1: the first specified number - 3.
int series2: the second specified number
Returns
int: the count of distinct numbers in the subarray
Examples
Example 1
array = [1, 2, 2, 2, 5, 2]series1 = 1series2 = 5return = 3The subarray must contain the series1 and series2 and having the smallest number of distinct values is [1, 2, 2, 2, 5], so return 3, the number of distinct integers in this subarray.
Example 2
array = [1, 3, 2, 1, 4]series1 = 1series2 = 2return = 2The shortest subarray contains both series1 and series2 is [2, 1], so we return 2, the number of distinct values in this subarray.
Example 3
array = [3, 1, 2]series1 = 1series2 = 1return = 1Because series1 and series2 are the same, so if the array contains series1, that would be good. This array contains series1, so we return 1.
Example 4
array = [2, 4, 9]series1 = 1series2 = 1return = 0Because series1 and series2 are the same, but this array doesn't contain series1, so we return 0.
Constraints
🍍🍍More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026