Common free meeting slots

A free medium coding practice problem. Solve it in JavaScript, TypeScript or Python and check your solution against fresh hidden tests — edge cases and random inputs — as often as you like.

Difficulty
Medium
Type
Function
Languages
JavaScript, TypeScript or Python

Problem

Find when everybody is free. calendars holds one list of busy intervals per person; each interval [start, end] is in minutes and half-open (busy from start up to, not including, end), intervals are unsorted, may overlap, and may reach outside the working day; intervals with start ≥ end mean nothing. Return the maximal intervals [start, end] inside the working day [dayStart, dayEnd] when nobody is busy and that last at least minLength minutes (minLength ≥ 1), in time order.

Function signature

// JavaScript
function freeSlots(calendars, dayStart, dayEnd, minLength)

// TypeScript
function freeSlots(calendars: any, dayStart: any, dayEnd: any, minLength: any): any

// Python
def free_slots(calendars, dayStart, dayEnd, minLength):

Examples

  1. freeSlots([[[540,600],[720,780]],[[570,630],[900,960]]], 480, 1020, 30) → [[480,540],[630,720],[780,900],[960,1020]]
  2. freeSlots([[[480,540]],[[600,660]],[[1000,1100]]], 480, 1020, 61) → [[660,1000]]

How checking works

Run your code against the examples above, then submit a check: it runs on the server against hidden tests built fresh each time, including edge cases and random inputs. Practice is untimed and never affects a verified score; when you are ready, take a graded coding challenge to earn a badge.

More practice problems

Next steps