Movie Schedule for Maximum Enjoyment
Updated
Problem statement
You have n movies. Movie i has a deadline deadlines[i] and an enjoyment value enjoyments[i]. You can watch movies on days 1, 2, ..., numDays.
- Watching a movie takes one whole day, and you can watch at most one movie per day.
- Movie
ican only be watched on a daydwithd <= deadlines[i]. Its deadline day itself is allowed. - Each movie can be watched at most once, and you may skip any movie.
Return the largest total enjoyment you can get from the movies you watch.
Function
maxTotalEnjoyment(deadlines: int[], enjoyments: int[], numDays: int) → longExamples
Example 1
deadlines = [3,1,2,1,3]enjoyments = [20,35,25,30,15]numDays = 3return = 80Movies 1 and 3 both have deadline 1, so only one of them fits. Watch movie 1 (enjoyment 35) on day 1. Days 2 and 3 are left. Watch movie 2 (enjoyment 25, deadline 2) on day 2 and movie 0 (enjoyment 20, deadline 3) on day 3. The total is 35 + 25 + 20 = 80. Movies 3 and 4 are skipped.
Example 2
deadlines = [5,5,5,2]enjoyments = [8,6,9,4]numDays = 2return = 17The deadlines are not the problem here: only days 1 and 2 exist, so you can watch just two movies. The two largest enjoyments are 9 (movie 2) and 8 (movie 0), for a total of 17.
Example 3
deadlines = [2,2,2]enjoyments = [10,10,10]numDays = 4return = 20There are four days, but every movie must be watched by day 2. Only two of the three movies fit, so the total is 10 + 10 = 20.
Constraints
1 <= deadlines.length <= 2000enjoyments.length == deadlines.length1 <= deadlines[i] <= 1051 <= enjoyments[i] <= 1091 <= numDays <= 105
More C3.ai interview questions
- Every Result of Grouping an ExpressionONSITE INTERVIEW · Seen Jan 2023
- Fewest Jumps to the Last IndexONSITE INTERVIEW · Seen Jan 2023
- Rotate a Square Grid ClockwiseONSITE INTERVIEW · Seen Jan 2023
- Days Until a Warmer DayPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
- Can All Courses Be FinishedONSITE INTERVIEW · Seen Nov 2021
- Longest Arithmetic SubsequenceONSITE INTERVIEW · Seen Feb 2021
- Gas Station LoopONSITE INTERVIEW · Seen Dec 2020
- Drop Recent Duplicate MessagesOA · Seen Oct 2026
- Maximum K-Star SumOA · Seen Oct 2026
- Fewest Turns to Open a Wheel LockPHONE SCREEN · Seen Nov 2024
Similar questions at other companies
- Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
- Select K Paired Indices for Maximum ScoreAmazon · ONSITE INTERVIEW
- Minimum Workers with Job AssignmentsLyft · ONSITE INTERVIEWLyft interview questions
- Allocate Customers to Preferred SitesYelp · ONSITE INTERVIEWYelp interview questions
- Minimum Refueling StopsUber · ONSITE INTERVIEWUber interview questions
- Maximum Number of Events That Can Be AttendedByteDance · PHONE SCREENByteDance interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Maximum Number of Events That Can Be AttendedSnowflake · PHONE SCREENSnowflake interview questions
- Rearrange Songs by AuthorZomato / Eternal · OAZomato / Eternal interview questions
- Schedule Unit-Time Jobs for the Most ProfitScale AI · PHONE SCREENScale AI interview questions