Compute Maximum Scheduled Tasks
Updated
Problem statement
At a high-paced analytics platform, efficiently scheduling tasks within designated time constraints is crucial. The system consists of n mandatory tasks and n optional tasks. Two arrays, mandatoryTasks and optionalTasks, specify the duration in hours of each task. Here, mandatoryTasks[i] indicates the time required for the i-th mandatory task, while optionalTasks[i] represents the duration of the i-th optional task.
Each workday has a strict limit of maxDailyHours, within which tasks must be scheduled. It is required that exactly one mandatory task is scheduled each day. If time permits, at most one optional task can also be included on the same day. The total time spent on a day cannot exceed maxDailyHours. The challenge is to determine the highest number of optional tasks that can be scheduled over the course of n days while adhering to these constraints.
Function
computeMaxScheduledTasks(maxDailyHours: int, mandatoryTasks: int[], optionalTasks: int[]) → int
Complete the function computeMaxScheduledTasks in the editor below.
computeMaxScheduledTasks has the following parameters:
int maxDailyHours: the maximum number of hours available each day.int mandatoryTasks[n]: an array representing the duration of mandatory tasks.int optionalTasks[n]: an array representing the duration of optional tasks.
Returns
int: the highest number of optional tasks that can be completed within the given constraints.
Examples
Example 1
maxDailyHours = 7mandatoryTasks = [4, 5, 2, 4]optionalTasks = [5, 6, 3, 4]return = 2Day 1: mandatory task 4 hours with the optional task of 3 hours (4 + 3 = 7). Day 2: mandatory task 5 hours alone. Day 3: mandatory task 2 hours with the optional task of 5 hours (2 + 5 = 7). Day 4: mandatory task 4 hours alone. That schedules 2 optional tasks. Three are impossible: the 6-hour optional task would need a mandatory task of at most 1 hour (there is none), and the 5-hour and 4-hour optional tasks both need the 2-hour mandatory task, so only one of them can be scheduled.
Constraints
1 <= n <= 2 * 10^5, wherenis the length of bothmandatoryTasksandoptionalTasks1 <= maxDailyHours <= 2 * 10^51 <= mandatoryTasks[i], optionalTasks[i] <= maxDailyHours
More Amazon interview questions
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximal SquareONSITE INTERVIEW · Seen Nov 2026
- Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
- Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
- Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
Similar questions at other companies
- Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
- Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
- Minimum Removals to Balance ArraySalesforce · OASalesforce interview questions
- Minimum Machines for TasksExpedia · OAExpedia interview questions
- Find Minimum Possible SizeMathWorks · OAMathWorks interview questions
- Minimum Days to Watch All MoviesAdobe · OAAdobe interview questions
- Efficient Janitor TripsRoblox · OARoblox interview questions
- Catch Fish with Reusable BaitsSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
- Can Every Package Fit in a BoxIMC Trading · OAIMC Trading interview questions
- Minimum Tunnel Crossing TimeArcesium · OAArcesium interview questions