Trains the technique from
LeetCode 436Find Right IntervalThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A depot logs its maintenance windows as windows, where windows[i] = [open_i, close_i] gives the offset in minutes, measured from the daily shift changeover, at which window i opens and the offset at which it closes. Offsets before the changeover are negative. Every window satisfies open_i <= close_i, and no two windows share an opening offset.
For each window i the dispatcher wants its follower: the window j whose opening offset is the smallest one that is still at least close_i. A window may be its own follower when its opening and closing offsets are equal. If no window opens at or after close_i, window i has no follower.
Return an array res of the same length as windows, where res[i] is the index of the follower of window i, or -1 when window i has no follower.
Example 1
Window 0 closes at 22, and window 2 opens at 23, the smallest opening offset that is at least 22. Window 1 closes at 3, and window 0 opens at 14, the smallest opening offset that is at least 3. Window 2 closes at 30 and no window opens at or after 30.
Example 2
Window 0 opens and closes at 7, so its own opening offset of 7 is at least its closing offset and it is its own follower. Window 1 closes at 12 and the only openings on record are 7 and 8, both below 12.
Example 3
Window 0 closes at -18 and window 1 opens at -18. Window 1 closes at 9 and the only opening at or after 9 is window 2's opening of 55. Window 2 closes at 61, later than every opening on record.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def next_window(windows: list[list[int]]) -> list[int]:public int[] nextWindow(int[][] windows)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.