Imagine you're a time management consultant helping someone maximize their value from attending events. You have a list of events, each with a start time, end time, and value they'll gain by attending.
Your goal is to select at most two non-overlapping events that maximize the total value. Events are considered overlapping if one starts before or when another ends - there must be at least a 1-unit gap between events.
Input: A 2D array events where events[i] = [startTime, endTime, value]
Output: The maximum sum of values from selecting up to 2 non-overlapping events
Example: If you have events [[1,3,2], [4,5,2], [2,4,3]], you could pick events 1 and 2 for a total value of 4, since event 1 ends at time 3 and event 2 starts at time 4.
Input & Output
Constraints
- 2 โค events.length โค 105
- events[i].length == 3
- 1 โค startTimei โค endTimei โค 109
- 1 โค valuei โค 106
- You can attend at most 2 events