Problem · Sorting

Filter Movies by Inclusive Year Range

Learn this problem
MediumSISusquehanna International GroupFULLTIMEPHONE SCREEN

Problem statement

Each entry in movies is a CSV row in the exact form title,year. Return the titles whose release year is between startYear and endYear, inclusive.

For this exercise, assume titles are nonempty and contain no comma. Return matching titles in ascending year order, breaking equal-year ties lexicographically by title.

Function

filterMoviesByYear(movies: String[], startYear: int, endYear: int) → String[]

Examples

Example 1

movies = ["Arrival,2016","Alien,1979","Dune,2021","Blade Runner,1982"]startYear = 1980endYear = 2020return = ["Blade Runner","Arrival"]

The inclusive range keeps the movies from 1982 and 2016, ordered by year.

Example 2

movies = ["Zeta,2000","Alpha,2000","Old,1999"]startYear = 2000endYear = 2000return = ["Alpha","Zeta"]

Both boundary-year movies match, and their titles break the tie.

Constraints

  • 0 <= movies.length <= 10^5
  • Every row contains one nonempty title without a comma and one valid integer year.
  • -10^4 <= startYear <= endYear <= 10^4

More Susquehanna International Group problems

drafts saved locally
public String[] filterMoviesByYear(String[] movies, int startYear, int endYear) {
    // Your code here
}
movies["Arrival,2016","Alien,1979","Dune,2021","Blade Runner,1982"]
startYear1980
endYear2020
expected["Blade Runner", "Arrival"]
checking account