A cinema hall has one screen and operates from 10 AM to 11 PM each day. Given its movie catalog and existing screenings, determine whether one additional movie of the requested duration can fit without changing or removing any existing screening.
public boolean canSchedule(int durationInMinutes, List<String> movies, List<String> screenings)
durationInMinutes: Duration of the movie to be added.movies: Each string is "title,duration", such as "Ocean Trail,180". Titles are unique and matched exactly, including letter case.screenings: Each string is "title,startTime", such as "Ocean Trail,600". The title identifies a movie in the catalog, which supplies its duration. A movie may have multiple screenings.true if the additional movie fits in at least one uninterrupted free interval; otherwise, return false. This method only checks availability and does not update the schedule.600; closing time is 1,380.startTime ends at startTime + duration. It must start at or after opening and finish at or before closing.0 ≤ movies.size() ≤ 1,0000 ≤ screenings.size() ≤ 7801 ≤ durationInMinutes ≤ 1,000; catalog durations satisfy the same bounds.1 and 100 characters and contain no commas. All records are correctly formatted, and all lists and strings are provided.movies. Existing screenings are non-overlapping and satisfy 600 ≤ startTime < endTime ≤ 1,380.Input: canSchedule(durationInMinutes = 120, movies = ["Ocean Trail,180", "City Lights,300", "Moon Ride,140"], screenings = ["City Lights,1080", "Ocean Trail,600", "Moon Ride,900"])
Output: true
Explanation: Ocean Trail ends at minute 780, and Moon Ride starts at minute 900. The new movie fits exactly in this 120-minute gap.
Input: canSchedule(durationInMinutes = 121, movies = ["Ocean Trail,180", "City Lights,300", "Moon Ride,140"], screenings = ["City Lights,1080", "Ocean Trail,600", "Moon Ride,900"])
Output: false
Explanation: The free gaps last 120 and 40 minutes. Although 160 minutes are free in total, neither gap can hold a 121-minute movie.
Input: canSchedule(durationInMinutes = 780, movies = [], screenings = [])
Output: true
Explanation: The movie can start at minute 600 and finish exactly at closing time, minute 1,380.
Input: canSchedule(durationInMinutes = 781, movies = [], screenings = [])
Output: false
Explanation: Only 780 minutes are available during opening hours.