2054. Two Best Non-Overlapping Events Medium
1/**
2 * [2054] Two Best Non-Overlapping Events
3 *
4 * You are given a 0-indexed 2D integer array of events where events[i] = [startTimei, endTimei, valuei]. The i^th event starts at startTimei and ends at endTimei, and if you attend this event, you will receive a value of valuei. You can choose at most two non-overlapping events to attend such that the sum of their values is maximized.
5 * Return this maximum sum.
6 * Note that the start time and end time is inclusive: 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 t, the next event must start at or after t + 1.
7 *
8 * Example 1:
9 * <img alt="" src="https://assets.leetcode.com/uploads/2021/09/21/picture5.png" style="width: 400px; height: 75px;" />
10 * Input: events = [[1,3,2],[4,5,2],[2,4,3]]
11 * Output: 4
12 * Explanation: Choose the green events, 0 and 1 for a sum of 2 + 2 = 4.
13 *
14 * Example 2:
15 * <img alt="Example 1 Diagram" src="https://assets.leetcode.com/uploads/2021/09/21/picture1.png" style="width: 400px; height: 77px;" />
16 * Input: events = [[1,3,2],[4,5,2],[1,5,5]]
17 * Output: 5
18 * Explanation: Choose event 2 for a sum of 5.
19 *
20 * Example 3:
21 * <img alt="" src="https://assets.leetcode.com/uploads/2021/09/21/picture3.png" style="width: 400px; height: 66px;" />
22 * Input: events = [[1,5,3],[1,5,1],[6,6,5]]
23 * Output: 8
24 * Explanation: Choose events 0 and 2 for a sum of 3 + 5 = 8.
25 *
26 * Constraints:
27 *
28 * 2 <= events.length <= 10^5
29 * events[i].length == 3
30 * 1 <= startTimei <= endTimei <= 10^9
31 * 1 <= valuei <= 10^6
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/two-best-non-overlapping-events/
37// discuss: https://leetcode.com/problems/two-best-non-overlapping-events/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn max_two_events(events: Vec<Vec<i32>>) -> i32 {
43 0
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_2054() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.