bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 436. Find Right Interval

436. Find Right Interval

Leetcode Solutions

Using TreeMap

  1. Create a TreeMap starts to store intervals' start points as keys and their indices as values.
  2. Iterate over the input intervals and populate the TreeMap with the start point and index of each interval.
  3. Create an array result to store the indices of the right intervals.
  4. For each interval in intervals, use the TreeMap's ceilingEntry method to find the least key greater than or equal to the interval's end point.
  5. If ceilingEntry returns a non-null value, store the corresponding index in result. Otherwise, store -1 to indicate no right interval exists.
  6. Return the result array.
UML Thumbnail

Brute Force

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...