You are given a list of tasks. Each task i is represented as [startᵢ, endᵢ, durationᵢ], meaning:
The task can only run during the time interval from startᵢ to endᵢ (inclusive).
It must be executed for exactly durationᵢ total seconds, but the execution does not have to be continuous.
The computer can run any number of tasks at once, and you may turn it on or off freely.
Your goal is to minimize the total number of seconds that the computer is turned on, while still finishing all tasks fully.
Return the minimum total active time required.
Input: tasks = [[1,4,2],[2,6,2]]
Output: 3
Explanation:
Task1 needs 2s within [1..4] Task2 needs 2s within [2..6] One optimal schedule: Run at times: {2,3,5} Total on-time = 3 seconds.
Input: tasks = [[3,4,1],[1,2,1],[5,7,2]]
Output: 3
Explanation:
Possible active seconds → {2,4,6} Total = 3 seconds.
Accepted:
Submission: