#2054
Two Best Non-Overlapping Events
specialist · 650 · lc medium +30 · verified · 64% accepted · 1,851 likes · top 67%
Description
Each event in the array events is represented as [startTime, endTime, value]. You may attend at most two non-overlapping events (if one ends at time t, the next must start at t + 1 or later). Return the maximum total value achievable by attending at most two events.
Example 1:
Input: events = [[1,3,2],[4,5,2],[2,4,3]]
Output: 4
Explanation: Choose the green events, 0 and 1 for a sum of 2 + 2 = 4.
Example 2:
Input: events = [[1,3,2],[4,5,2],[1,5,5]]
Output: 5
Explanation: Choose event 2 for a sum of 5.
Example 3:
Input: events = [[1,5,3],[1,5,1],[6,6,5]]
Output: 8
Explanation: Choose events 0 and 2 for a sum of 3 + 5 = 8.
Code
1
2
3