3414. Maximum Score of Non-overlapping Intervals Hard

@problem@discussion
#Array#Binary Search#Dynamic Programming#Sorting



1/**
2 * [3414] Maximum Score of Non-overlapping Intervals
3 *
4 * You are given a 2D integer array intervals, where intervals[i] = [li, ri, weighti]. Interval i starts at position li and ends at ri, and has a weight of weighti. You can choose up to 4 non-overlapping intervals. The score of the chosen intervals is defined as the total sum of their weights.
5 * Return the <span data-keyword="lexicographically-smaller-array">lexicographically smallest</span> array of at most 4 indices from intervals with maximum score, representing your choice of non-overlapping intervals.
6 * Two intervals are said to be non-overlapping if they do not share any points. In particular, intervals sharing a left or right boundary are considered overlapping.
7 *  
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">intervals = [[1,3,2],[4,5,2],[1,5,5],[6,9,3],[6,7,1],[8,9,1]]</span>
11 * Output: <span class="example-io">[2,3]</span>
12 * Explanation:
13 * You can choose the intervals with indices 2, and 3 with respective weights of 5, and 3.
14 * </div>
15 * <strong class="example">Example 2:
16 * <div class="example-block">
17 * Input: <span class="example-io">intervals = [[5,8,1],[6,7,7],[4,7,3],[9,10,6],[7,8,2],[11,14,3],[3,5,5]]</span>
18 * Output: <span class="example-io">[1,3,5,6]</span>
19 * Explanation:
20 * You can choose the intervals with indices 1, 3, 5, and 6 with respective weights of 7, 6, 3, and 5.
21 * </div>
22 *  
23 * Constraints:
24 * 
25 * 	1 <= intevals.length <= 5 * 10^4
26 * 	intervals[i].length == 3
27 * 	intervals[i] = [li, ri, weighti]
28 * 	1 <= li <= ri <= 10^9
29 * 	1 <= weighti <= 10^9
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/maximum-score-of-non-overlapping-intervals/
35// discuss: https://leetcode.com/problems/maximum-score-of-non-overlapping-intervals/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn maximum_weight(intervals: Vec<Vec<i32>>) -> Vec<i32> {
41        vec![]
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_3414() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.