33 · Intervals

#759 Employee Free Time

frequently reported atAirbnbGoogle

the problem

In plain words

schedule.get(i) is employee i's list of working intervals [start, end]; each list is sorted and its intervals don't overlap. Return, in sorted order, every finite stretch of positive length when no employee is working. Intervals are Interval objects with public start and end fields. Touching intervals such as [1,2] and [2,3] leave no free time between them.

in schedule = [[[1,2],[5,6]],[[1,3]],[[4,10]]]

out [[3,4]]

Someone is busy over [1,3] and over [4,10]. The time before 1 and after 10 is endless, so it doesn't count.

in schedule = [[[1,3],[6,7]],[[2,4]],[[2,5],[9,12]]]

out [[5,6],[7,9]]

  • 1 ≤ schedule.length, schedule[i].length ≤ 50
  • 0 ≤ start < end ≤ 10⁸

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code right here. Stuck for 20 minutes? Open one hint at a time.

This one is LeetCode Premium. You don't need a subscription: solve it right here. The free alternative linked above is the closest free practice; its label says how close it is.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #56
      Merge Intervals
      Mediumin Intervals
    2. #23
    3. #253
      Meeting Rooms II
      Mediumin IntervalsLeetCode Premium