You are given an array intervals, where intervals[i] = [start, end, reward] occupies the inclusive day range start to end and pays reward if selected.
Select intervals so that no two selected intervals share a day (after one ends on day d, the next may start no earlier than day d + 1) and the total reward is maximized.
Return the maximum total reward.
Examples
Example 1
Input: intervals = [[2,4,4],[3,6,6],[6,8,2],[5,7,3]]
Output: 7
Explanation: Select [2,4,4] and [5,7,3] for 4 + 3 = 7. The 6-reward interval blocks days 3-6, leaving at most 6 + nothing compatible except [6,8,2]... which shares day 6, so 7 is optimal.
Example 2
Input: intervals = [[1,3,5],[3,5,5]]
Output: 5
Explanation: Both intervals use day 3, so only one can be selected.
Constraints
1≤intervals.length≤2⋅105
intervals[i].length=3
1≤start≤end≤109
1≤reward≤109
Loading editor...
Log in to run your code. Your draft is saved in this browser.Log inSign up