757. Set Intersection Size At Least Two Hard

@problem@discussion
#Array#Greedy#Sorting



1/**
2 * [757] Set Intersection Size At Least Two
3 *
4 * You are given a 2D integer array intervals where intervals[i] = [starti, endi] represents all the integers from starti to endi inclusively.
5 * A containing set is an array nums where each interval from intervals has at least two integers in nums.
6 * 
7 * 	For example, if intervals = [[1,3], [3,7], [8,9]], then [1,2,4,7,8,9] and [2,3,4,8,9] are containing sets.
8 * 
9 * Return the minimum possible size of a containing set.
10 *  
11 * <strong class="example">Example 1:
12 * 
13 * Input: intervals = [[1,3],[3,7],[8,9]]
14 * Output: 5
15 * Explanation: let nums = [2, 3, 4, 8, 9].
16 * It can be shown that there cannot be any containing array of size 4.
17 * 
18 * <strong class="example">Example 2:
19 * 
20 * Input: intervals = [[1,3],[1,4],[2,5],[3,5]]
21 * Output: 3
22 * Explanation: let nums = [2, 3, 4].
23 * It can be shown that there cannot be any containing array of size 2.
24 * 
25 * <strong class="example">Example 3:
26 * 
27 * Input: intervals = [[1,2],[2,3],[2,4],[4,5]]
28 * Output: 5
29 * Explanation: let nums = [1, 2, 3, 4, 5].
30 * It can be shown that there cannot be any containing array of size 4.
31 * 
32 *  
33 * Constraints:
34 * 
35 * 	1 <= intervals.length <= 3000
36 * 	intervals[i].length == 2
37 * 	0 <= starti < endi <= 10^8
38 * 
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/set-intersection-size-at-least-two/
43// discuss: https://leetcode.com/problems/set-intersection-size-at-least-two/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48    pub fn intersection_size_two(intervals: Vec<Vec<i32>>) -> i32 {
49        0
50    }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn test_757() {
61    }
62}
63


Back
© 2025 bowen.ge All Rights Reserved.