mediumDynamic ProgrammingPattern: Mixed

Maximum Profit from Scheduled Deliveries Solution

Problem Statement

Given a list of delivery tasks with their respective profits and deadlines, determine the maximum profit that can be achieved by scheduling these tasks without exceeding their deadlines, considering that each task can only be scheduled once and tasks cannot be scheduled in parallel.

Examples

Example 1:
Input:[{"profit": 10, "deadline": 2}, {"profit": 20, "deadline": 1}, {"profit": 15, "deadline": 3}]
Output:35
Explanation: Schedule the task with profit 20 on day 1 and the task with profit 15 on day 2 to achieve a maximum profit of 35.
Example 2:
Input:[{"profit": 5, "deadline": 3}, {"profit": 8, "deadline": 2}, {"profit": 12, "deadline": 1}]
Output:20
Explanation: Schedule the task with profit 12 on day 1 and the task with profit 8 on day 2 to achieve a maximum profit of 20.

Constraints

  • The number of tasks will not exceed 10^4.
  • Each task's profit and deadline will be positive integers.
  • The deadlines of tasks will not exceed 10^4.
  • The maximum possible profit will not exceed 10^6.
Time: O(n^2) Space: O(n)
The optimized approach uses dynamic programming to efficiently track the maximum achievable profit at each deadline, avoiding redundant computations and ensuring an optimal scheduling strategy with a time complexity of O(n^2).

Run, Test & Submit Code

Ready to practice this challenge? Launch our interactive compilation environment with compiler validation.

Solve on Interactive Workspace

Tested Solutions

No solution code is currently loaded.
Complete this code in the workspace editor.