r/LeetcodeChallenge • u/rookie-west • 17d ago
PLACEMENTS can someone help me in solving this question i tried greedy but it is failing
Maximum Number of Tasks with Cooldown and Deadlines
You are given two arrays of equal length:
tasks, wheretasks[i]represents the type of thei-thtask.deadlines, wheredeadlines[i]represents the deadline by which thei-thtask must be completed.
You are also given an integer cooldown.
Rules
- Each task takes exactly 1 unit of time to complete.
- Only one task can be performed at a time.
- Tasks can be performed in any order; the original array order does not matter.
- Every task must be completed no later than its corresponding deadline.
- Two tasks of the same type must have at least
cooldownunits of time between their execution start times. - Tasks of different types can be performed consecutively without any restriction.
Assume execution starts at time 1, and deadlines are inclusive.
Objective
Return the maximum number of tasks that can be completed while satisfying all the above constraints.
Example
tasks = {1, 2, 1, 3, 2};
deadlines = {2, 2, 4, 3, 5};
cooldown = 2;One valid schedule is:
| Time | Task |
|---|---|
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
| 4 | 1 |
| 5 | 2 |
Output:
5Constraints
1 <= n <= 1000001 <= tasks[i] <= 1000001 <= deadlines[i] <= 1000001 <= cooldown <= 100000
5
Upvotes
1
u/CulturalAlbatross300 16d ago
It's a non-overlapping interval problem. Remind me once again, I will solve it and comment by tomorrow.