436. Find Right Interval Medium
1/**
2 * [436] Find Right Interval
3 *
4 * You are given an array of intervals, where intervals[i] = [starti, endi] and each starti is unique.
5 * The right interval for an interval i is an interval j such that startj >= endi and startj is minimized. Note that i may equal j.
6 * Return an array of right interval indices for each interval i. If no right interval exists for interval i, then put -1 at index i.
7 *
8 * Example 1:
9 *
10 * Input: intervals = [[1,2]]
11 * Output: [-1]
12 * Explanation: There is only one interval in the collection, so it outputs -1.
13 *
14 * Example 2:
15 *
16 * Input: intervals = [[3,4],[2,3],[1,2]]
17 * Output: [-1,0,1]
18 * Explanation: There is no right interval for [3,4].
19 * The right interval for [2,3] is [3,4] since start0 = 3 is the smallest start that is >= end1 = 3.
20 * The right interval for [1,2] is [2,3] since start1 = 2 is the smallest start that is >= end2 = 2.
21 *
22 * Example 3:
23 *
24 * Input: intervals = [[1,4],[2,3],[3,4]]
25 * Output: [-1,2,-1]
26 * Explanation: There is no right interval for [1,4] and [3,4].
27 * The right interval for [2,3] is [3,4] since start2 = 3 is the smallest start that is >= end1 = 3.
28 *
29 *
30 * Constraints:
31 *
32 * 1 <= intervals.length <= 2 * 10^4
33 * intervals[i].length == 2
34 * -10^6 <= starti <= endi <= 10^6
35 * The start point of each interval is unique.
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/find-right-interval/
41// discuss: https://leetcode.com/problems/find-right-interval/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn find_right_interval(intervals: Vec<Vec<i32>>) -> Vec<i32> {
47 vec![]
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_436() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.