Problem · Array

TV Shows Produced During a Period

Learn this problem
EasyRippling logoRipplingFULLTIMEOA

Problem statement

A TV-series service provides one record for each show. For an offline coding exercise, the records are represented by three parallel arrays:

  • names[i] is the name of show i.
  • showStartYears[i] is the year when show i began production.
  • showEndYears[i] is the year when show i ended production, or -1 if it is still in production.

Return the names of shows that satisfy the requested period rule, sorted in ascending lexicographic order.

  • If endYear == -1, select exactly the shows that are still in production and have showStartYears[i] >= startYear.
  • Otherwise, select exactly the completed shows whose complete production period lies within the requested interval: showStartYears[i] >= startYear and showEndYears[i] <= endYear.

Function

findShowsProducedInPeriod(names: String[], showStartYears: int[], showEndYears: int[], startYear: int, endYear: int) → String[]

Examples

Example 1

names = ["Alpha","Beta","Gamma"]showStartYears = [2010,2018,2020]showEndYears = [2015,-1,-1]startYear = 2017endYear = -1return = ["Beta","Gamma"]

Beta and Gamma are both still in production and began no earlier than 2017.

Example 2

names = ["Blue Sky","Archive","Current"]showStartYears = [2012,2015,2010]showEndYears = [2018,2016,-1]startYear = 2013endYear = 2019return = ["Archive"]

Archive is fully contained in 2013 through 2019. Blue Sky began too early, and Current is not completed.

Example 3

names = ["Zulu","Alpha","Beta"]showStartYears = [2015,2016,2017]showEndYears = [2018,2019,2020]startYear = 2015endYear = 2020return = ["Alpha","Beta","Zulu"]

All three production periods fit inside the request, so their names are returned in lexicographic order.

Constraints

  • 1 <= names.length <= 10^5
  • names.length == showStartYears.length == showEndYears.length
  • 1900 <= showStartYears[i] <= 3000
  • showEndYears[i] == -1 or showStartYears[i] <= showEndYears[i] <= 3000
  • endYear == -1 or startYear <= endYear
  • Each name is non-empty and contains only English letters, digits, and spaces.

More Rippling problems

drafts saved locally
public String[] findShowsProducedInPeriod(String[] names, int[] showStartYears, int[] showEndYears, int startYear, int endYear) {
    // write your code here
}
names["Alpha","Beta","Gamma"]
showStartYears[2010,2018,2020]
showEndYears[2015,-1,-1]
startYear2017
endYear-1
expected["Beta", "Gamma"]
checking account