Problem
Ask
Submissions

Problem: Find Right Interval

Medium
30 min
Understand how to identify the smallest right interval for each given interval using heaps. This lesson helps you practice solving interval scheduling problems efficiently by leveraging heap data structures, improving your ability to approach dynamic data and optimization questions in coding interviews.

Statement

You are given an array of intervals where each interval is represented by a pair [starti,endi][start_i, end_i]. The startistart_i values are unique, meaning no two intervals begin at the same time.

The task is to find the right interval for each interval in the list. The right interval for an interval ii is an interval jj such that startj>=endistart_j >= end_i and startjstart_j is minimized (i.e., it is the smallest start time among all valid intervals that is greater than or equal to endiend_i). Note that ii may equal jj.

Return an array of right interval indexes for each interval ii. If no right interval exists for interval ii, then put 1-1 at index ii.

Constraints:

  • 11 \leq intervals.length 1000\leq 1000

  • intervals[i].length ==2== 2

  • 106startiendi106-10^6 \leq start_i \leq end_i \leq 10^6

  • The start times are guaranteed to be unique.

Problem
Ask
Submissions

Problem: Find Right Interval

Medium
30 min
Understand how to identify the smallest right interval for each given interval using heaps. This lesson helps you practice solving interval scheduling problems efficiently by leveraging heap data structures, improving your ability to approach dynamic data and optimization questions in coding interviews.

Statement

You are given an array of intervals where each interval is represented by a pair [starti,endi][start_i, end_i]. The startistart_i values are unique, meaning no two intervals begin at the same time.

The task is to find the right interval for each interval in the list. The right interval for an interval ii is an interval jj such that startj>=endistart_j >= end_i and startjstart_j is minimized (i.e., it is the smallest start time among all valid intervals that is greater than or equal to endiend_i). Note that ii may equal jj.

Return an array of right interval indexes for each interval ii. If no right interval exists for interval ii, then put 1-1 at index ii.

Constraints:

  • 11 \leq intervals.length 1000\leq 1000

  • intervals[i].length ==2== 2

  • 106startiendi106-10^6 \leq start_i \leq end_i \leq 10^6

  • The start times are guaranteed to be unique.