BackmediumDynamic ProgrammingCredPaytm

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.

Example 1
Input
[[1, 2, 3], [2, 4, 5], [3, 6, 7]]
Output
12

Explanation: Step-by-step: We can schedule task with profit 2 on day 2 and task with profit 10 on day 3. So, the maximum profit is 2 + 10 = 12.

Example 2
Input
[[1, 2, 3], [2, 4, 5], [3, 6, 7]]
Output
6

Explanation: Step-by-step: We can schedule task with profit 1 on day 1, task with profit 2 on day 2, and task with profit 3 on day 3. So, the maximum profit is 1 + 2 + 3 = 6.

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.
Live Compiler1 Free Run Available
Loading Editor...
Test Cases & Output
Click "Run" to test your 1 free compile trial!

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free

Maximum Profit from Scheduled Deliveries — Problem Statement & Solution Guide

Dynamic ProgrammingMediumMixed
TimeO(n log n)
|
SpaceO(n)

Problem Description

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

[[1, 2, 3], [2, 4, 5], [3, 6, 7]]

Output

12

Explanation: Step-by-step: We can schedule task with profit 2 on day 2 and task with profit 10 on day 3. So, the maximum profit is 2 + 10 = 12.

Example 2

Input

[[1, 2, 3], [2, 4, 5], [3, 6, 7]]

Output

6

Explanation: Step-by-step: We can schedule task with profit 1 on day 1, task with profit 2 on day 2, and task with profit 3 on day 3. So, the maximum profit is 1 + 2 + 3 = 6.

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.

Optimal Approach & Strategy

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).

Brute Force Approach

The brute-force approach would involve generating all possible permutations of tasks and calculating the total profit for each permutation, selecting the one that yields the highest profit without exceeding deadlines.

Verified Code Solutions

No solution currently available for JavaScript. Select another language tab above.

Asked in Top Tech Interviews

CredPaytm

Solve in Interative Editor

Ready to test your code? Open our built-in compiler, run custom test suites, and see detailed complexity analysis reports instantly.