Most Movie Screenings on One Screen
Updated
Problem statement
A cinema has one screen and a list of movies. Movie i lasts movieLength[i] hours and, if it is shown, must start at hour screeningTime[i], so it uses the screen during [screeningTime[i], screeningTime[i] + movieLength[i]).
Two screenings cannot overlap, but one may start at the exact hour the previous one ends. Return the largest number of movies that can be shown.
Function
maxScreenings(movieLength: int[], screeningTime: int[]) → intExamples
Example 1
movieLength = [3,1,2,2,1]screeningTime = [0,1,2,4,3]return = 3The movies run during [0, 3), [1, 2), [2, 4), [4, 6) and [3, 4). Showing [1, 2), [2, 4) and [4, 6) back to back gives 3 screenings. Four is impossible: [0, 3) overlaps [1, 2) and [2, 4), and [2, 4) overlaps [3, 4), so at most three of the five fit together.
Example 2
movieLength = [5,1,1]screeningTime = [0,1,3]return = 2The long movie [0, 5) overlaps both short ones. Skipping it and showing [1, 2) and [3, 4) gives 2.
Example 3
movieLength = [2,2]screeningTime = [7,7]return = 1Both movies want hours 7 to 9, so only one can be shown.
Constraints
1 <= movieLength.length <= 5000andscreeningTime.length == movieLength.length1 <= movieLength[i] <= 10^90 <= screeningTime[i] <= 2 * 10^9
More Adobe Phone Screen questions
- Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
- All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
- Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
- Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
- Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
- Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
- Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
- Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
- Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
- Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026
Similar questions at other companies
- Minimum Removals for Non-Overlapping IntervalsByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions
- Minimum Appointment Cancellations with a Required BreakMaven Clinic · PHONE SCREENMaven Clinic interview questions
- Minimum Meeting RoomsSentry · PHONE SCREENSentry interview questions
- Reschedule k Meetings to Find Maximum Break TimeGoogle · PHONE SCREENGoogle interview questions
- Maximum Compatible Time WindowsIBM · OAIBM interview questions
- Minimum Railway PlatformsMakeMyTrip.com · ONSITE INTERVIEWMakeMyTrip.com interview questions
- Task SchedulingJP Morgan Chase · OAJP Morgan Chase interview questions
- Maximum Non-Overlapping IntervalsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Minimum Workers with Job AssignmentsLyft · ONSITE INTERVIEWLyft interview questions