Google questions

Exactly x Meetings

GoogleOnsiteMedium

Each meeting is given as [start, end] and is active on the half-open time range [start, end).

Part 1: Exactly x Meetings

You are given a list of meetings, where each meeting is [start, end]. A meeting is active on the half-open range [start, end): active at its start time, not at its end time. A meeting with start == end is never active.

Return every maximal interval during which exactly x meetings are active at the same time, as [low, high] pairs in chronological order. Returned intervals are half-open like the meetings, and two returned intervals never touch: when a meeting ends at the same instant another starts, the count does not change there, and the stretch on both sides is reported as one interval.

If no time has exactly x active meetings, return an empty list.

  1. Example 1
    x
    2
    meetings
    [[1,4],[2,5],[4,6]]
    Output
    [[2,5]]

    Why: One meeting is active on [1, 2), two on [2, 4), and still two on [4, 5): the meeting ending at 4 is replaced by the one starting at 4. The two stretches with count 2 merge into the single interval [2, 5); on [5, 6) only one meeting is active.

Constraints

  • 0 <= len(meetings) <= 10^5
  • 0 <= meetings[i][0] <= meetings[i][1] <= 10^9
  • 1 <= x <= len(meetings) + 1
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question