Class Solution
java.lang.Object
g2001_2100.s2054_two_best_non_overlapping_events.Solution
2054 - Two Best Non-Overlapping Events.<p>Medium</p>
<p>You are given a <strong>0-indexed</strong> 2D integer array of <code>events</code> where <code>events[i] = [startTime<sub>i</sub>, endTime<sub>i</sub>, value<sub>i</sub>]</code>. The <code>i<sup>th</sup></code> event starts at <code>startTime<sub>i</sub></code> and ends at <code>endTime<sub>i</sub></code>, and if you attend this event, you will receive a value of <code>value<sub>i</sub></code>. You can choose <strong>at most</strong> <strong>two</strong> <strong>non-overlapping</strong> events to attend such that the sum of their values is <strong>maximized</strong>.</p>
<p>Return <em>this <strong>maximum</strong> sum.</em></p>
<p>Note that the start time and end time is <strong>inclusive</strong>: that is, you cannot attend two events where one of them starts and the other ends at the same time. More specifically, if you attend an event with end time <code>t</code>, the next event must start at or after <code>t + 1</code>.</p>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/09/21/picture5.png" alt="" /></p>
<p><strong>Input:</strong> events = [[1,3,2],[4,5,2],[2,4,3]]</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong> Choose the green events, 0 and 1 for a sum of 2 + 2 = 4.</p>
<p><strong>Example 2:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/09/21/picture1.png" alt="Example 1 Diagram" /></p>
<p><strong>Input:</strong> events = [[1,3,2],[4,5,2],[1,5,5]]</p>
<p><strong>Output:</strong> 5</p>
<p><strong>Explanation:</strong> Choose event 2 for a sum of 5.</p>
<p><strong>Example 3:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2021/09/21/picture3.png" alt="" /></p>
<p><strong>Input:</strong> events = [[1,5,3],[1,5,1],[6,6,5]]</p>
<p><strong>Output:</strong> 8</p>
<p><strong>Explanation:</strong> Choose events 0 and 2 for a sum of 3 + 5 = 8.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 <= events.length <= 10<sup>5</sup></code></li>
<li><code>events[i].length == 3</code></li>
<li><code>1 <= startTime<sub>i</sub> <= endTime<sub>i</sub> <= 10<sup>9</sup></code></li>
<li><code>1 <= value<sub>i</sub> <= 10<sup>6</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxTwoEvents
public int maxTwoEvents(int[][] events)
-