Description
Solutions
Amazon Care Get Minimum Score
πŸ”₯ FULLTIME

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 Description

Complete the function findSubarrayWithMinimumDistinctIntegers in the editor.

findSubarrayWithMinimumDistinctIntegers has the following parameters:

  1. 1. int[] array: an array of integers
  2. 2. int series1: the first specified number
  3. 3. int series2: the second specified number

Returns

int: the count of distinct numbers in the subarray

Example 1:

Input:  array = [1, 2, 2, 2, 5, 2], series1 = 1, series2 = 5
Output: 3
Explanation:
The 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:

Input:  array = [1, 3, 2, 1, 4], series1 = 1, series2 = 2
Output: 2
Explanation:
The shortest subarray contains both series1 and series2 is [2, 1], so we return 2, the number of distinct values in this subarray.

Example 3:

Input:  array = [3, 1, 2], series1 = 1, series2 = 1
Output: 1
Explanation:
Because 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:

Input:  array = [2, 4, 9], series1 = 1, series2 = 1
Output: 0
Explanation:
Because series1 and series2 are the same, but this array doesn't contain series1, so we return 0.
Constraints:
    🍍🍍
Thumbnail 0
Testcase

Result
Case 1

input:

output: