Optimal Task Scheduling
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 Description
Complete the function scheduleTasks in the editor below.
computeMaxScheduledTasks has the following parameters:
1. int maxDailyHours: the maximum number of hours available each day.
2. int mandatoryTasks[n]: an array representing the duration of mandatory tasks.
3. 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.
Example:
Input: maxDailyHours = 7, mandatoryTasks = [4, 5, 2, 4], optionalTasks = [5, 6, 3, 4]
Output: 2
Explanation:
Day 1: Schedule the first mandatory task (4 hours) and the third optional task (3 hours). Total: 4 + 3 = 7 hours.
Day 2: Schedule the second mandatory task (5 hours). No optional task can be added. Total: 5 hours.
Day 3: Schedule the third mandatory task (2 hours) and the first optional task (5 hours). Total: 2 + 5 = 7 hours.
Day 4: Schedule the fourth mandatory task (4 hours). No optional task can be added. Total: 4 hours.
After optimizing task scheduling, the maximum number of optional tasks that can be included is 2.
Constraints:
1 ≤ n, maxDailyHours ≤ 2*10^5
1 ≤ mandatoryTasks[i], optionalTasks[i] ≤ maxDailyHours
Get one-to-one training from Google Facebook engineers
Top-notch Professionals
Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.
Customized Private Class
Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.