Skip to interview prep
Apexed
Problem list123 / 143

123. Find a Continuous Key Overlap

MediumIntervals

Each key is active over a half-open interval [start, end). A rotation has enough overlap at time t if at least minimum keys are active.

Return [start, end] for the longest continuous span with enough overlap. When lengths tie, keep the earliest. Return an empty list if no positive-length span qualifies.

Example 1

Input: intervals = [[1,6],[3,5],[5,9]], minimum = 2
Output: [3,6]

Example 2

Input: intervals = [[0,2],[0,2],[5,7],[5,7]], minimum = 2
Output: [0,2]

Constraints

  • At most 100,000 intervals. Integer endpoints satisfy 0 ≤ start < end ≤ 10⁹.
  • 1 ≤ minimum ≤ 100,000. Keys can share the same interval.

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 6 hidden and sample tests.

Code runs in an isolated browser sandbox. Progress and submissions are saved on this device.

Find a Continuous Key Overlap — coding interview practice — Apexed