All problems
0117MediumArrayTwo PointersSweep Line

Shared Observation Windows

Tracked in this browser only
Write code

Trains the technique from

LeetCode 986Interval List Intersections

This 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.

Two telescopes, one under the dome and one out on the ridge, each publish tonight's clear-sky windows as minute marks counted from dusk. dome and ridge hold those windows as [opens, closes] pairs, already ordered by opening mark, and no two windows in the same schedule ever touch: every window closes strictly before the next one in that schedule opens.

A paired reading needs both telescopes clear at once. Report every stretch of time that both schedules cover, again as [opens, closes] pairs ordered by opening mark. A stretch that comes down to a single minute mark, where opens equals closes, still counts as coverage and must be reported.

Either schedule may be empty, though not both. When the two schedules never coincide, return an empty list.

Examples

Example 1

Input
dome = [[2, 6], [10, 14]], ridge = [[6, 9], [13, 20]]
Output
[[6, 6], [13, 14]]

The first two windows meet only at mark 6, which still counts, and the later pair overlaps from mark 13 until the dome window closes at 14.

Example 2

Input
dome = [[2, 20]], ridge = [[3, 5], [8, 9], [12, 25]]
Output
[[3, 5], [8, 9], [12, 20]]

One long dome window swallows the first two ridge windows whole and clips the third at mark 20.

Example 3

Input
dome = [[1, 2]], ridge = [[3, 4]]
Output
[]

The dome window has already closed before the ridge window opens, so nothing is covered twice.

Constraints

  • 0 <= dome.length, ridge.length <= 1000
  • dome.length + ridge.length >= 1
  • 0 <= opens < closes <= 10^9 for every window
  • Within one schedule the windows are sorted and disjoint: each window's closing mark is strictly less than the next window's opening mark.

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def shared_windows(dome: list[list[int]], ridge: list[list[int]]) -> list[list[int]]:
Java
public int[][] sharedWindows(int[][] dome, int[][] ridge)
September 7
Apply