Problem · Sliding Window

Get Minimum Watch Score

Learn this problem
MediumAmazonFULLTIMEOA
See Amazon hiring insights

Problem statement

Data analysts at Amazon are studying the trends in movies and shows popular on Prime Video in order to enhance the user experience.

They have identified the best critic-rated and the best audience-rated web series, represented by integer IDs series1, and series2. They also define the watch score of a contiguous period of some days as the number of distinct series watched by a viewer during that period.

Given an array watch_history, of size n, that represents the web series watched by a viewer over a period of n days, and two integers, series1 and series2, report the minimum watch score of a contiguous period of days in which both series1 and series2 have been viewed at least once. If series1 and series2 are the same value, one occurrence during the period is sufficient.

Function

getMinScore(watch_history: int[], series1: int, series2: int) → int

Complete the function getMinScore in the editor.

getMinScore has the following parameters:

  1. 1. int[] watch_history: an array of integers representing the web series watched each day
  2. 2. int series1: an integer representing the ID of the best critic-rated web series
  3. 3. int series2: an integer representing the ID of the best audience-rated web series

Returns

int: the minimum watch score of a contiguous period of days in which both series have been viewed at least once

Examples

Example 1

watch_history = [1, 3, 2, 1, 4]series1 = 1series2 = 2return = 2
Example 1 illustration

The contiguous periods of days in which series1 and series2 have been viewed at least once are:

Return the minimum watch score, 2.

Example 2

watch_history = [1, 2, 3, 5, 1]series1 = 5series2 = 5return = 2
🐻

Example 3

watch_history = [1, 2, 2, 2, 5, 2]series1 = 1series2 = 5return = 3
🐻‍❄️

Constraints

🐻‍❄️🐻

More Amazon problems

drafts saved locally
public int getMinScore(int[] watch_history, int series1, int series2) {
  // write your code here
}
watch_history[1, 3, 2, 1, 4]
series11
series22
expected2
checking account