Skip to the code
cf.
+25 XP

#585 Shared Free Slots of Two Calendars

medium

A scheduling assistant compares the free time of two people. Each person's free slots are a list of [start, end] ranges (both ends included), sorted by start, with no two slots in the same list overlapping or touching.

Write sharedSlots(mine, theirs) that returns every range of time that is free for both people, sorted by start. A shared moment of zero length, like [5, 5], still counts.

Example 1

Input: mine = [[0,2],[5,10],[13,23],[24,25]], theirs = [[1,5],[8,12],[15,24],[25,26]]
Output: [[1,2],[5,5],[8,10],[15,23],[24,24],[25,25]]

For example [5, 10] and [8, 12] share [8, 10].

Example 2

Input: mine = [[1,3],[5,9]], theirs = []
Output: []

The second person has no free time.

Constraints

  • 0 <= mine.length, theirs.length <= 100000
  • 0 <= start <= end <= 10^9
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).