Skip to content

Instantly share code, notes, and snippets.

@marcelowa
Last active May 18, 2026 05:45
Show Gist options
  • Select an option

  • Save marcelowa/2f911e21aeb53fd9d5328c3ce60e8415 to your computer and use it in GitHub Desktop.

Select an option

Save marcelowa/2f911e21aeb53fd9d5328c3ce60e8415 to your computer and use it in GitHub Desktop.
Meeting room

Instructions

Create a meeting manager that has the following functionalities. Given a list of meeting times, check if any of them overlap. Return the minimum number of rooms required to accommodate all the meetings.

Boilerplate

class MeetingsManager {
  public addMeeting(startTime: number, endTime: number): void {}
  public hasOverlappingTimes(): boolean {
    return false;
  }
  public minMeetingRooms(): number {
    return -1;
  }
}

Example usage

Suppose we use interval (start, end) to denote the start and end time of the meeting, we have the following meeting times: (1,4), (4,5), (6,8), (2,6)

In the above example, we should return true for the first question since (1, 4) and (2, 6) have overlaps. The minimum number of rooms for the example is 2.

const meetingsManager = new MeetingsManager();
meetingsManager.addMeeting(1, 4);
meetingsManager.addMeeting(4, 5);
meetingsManager.addMeeting(6, 8);
meetingsManager.addMeeting(2, 6);
console.log('Do any of the meetings overlap? ' + meetingsManager.hasOverlappingTimes());
console.log('Minimum number of rooms required: ' + meetingsManager.minMeetingRooms());

// Output should be:
// Do any of the meetings overlap? true
// Minimum number of rooms required: 2

Playground

https://runjs.app/play/#Y2xhc3MgTWVldGluZ3NNYW5hZ2VyIHsKICBwdWJsaWMgYWRkTWVldGluZyhtZWV0aW5nKTogdm9pZCB7fQogIHB1YmxpYyBoYXNPdmVybGFwcGluZ1RpbWVzKCk6IGJvb2xlYW4gewogICAgcmV0dXJuIGZhbHNlOwogIH0KICBwdWJsaWMgbWluTWVldGluZ1Jvb21zKCk6IG51bWJlciB7CiAgICByZXR1cm4gLTE7CiAgfQp9CgoKCmNvbnN0IG1lZXRpbmdzTWFuYWdlciA9IG5ldyBNZWV0aW5nc01hbmFnZXIoKTsKbWVldGluZ3NNYW5hZ2VyLmFkZE1lZXRpbmcoWzEsIDRdKTsKbWVldGluZ3NNYW5hZ2VyLmFkZE1lZXRpbmcoWzQsIDVdKTsKbWVldGluZ3NNYW5hZ2VyLmFkZE1lZXRpbmcoWzYsIDhdKTsKbWVldGluZ3NNYW5hZ2VyLmFkZE1lZXRpbmcoWzIsIDZdKTsKY29uc29sZS5sb2coIkRvIGFueSBvZiB0aGUgbWVldGluZ3Mgb3ZlcmxhcD8gIiArIG1lZXRpbmdzTWFuYWdlci5oYXNPdmVybGFwcGluZ1RpbWVzKCkpOwpjb25zb2xlLmxvZygiTWluaW11bSBudW1iZXIgb2Ygcm9vbXMgcmVxdWlyZWQ6ICIgKyBtZWV0aW5nc01hbmFnZXIubWluTWVldGluZ1Jvb21zKCkpOwoKCi8vIERvIGFueSBvZiB0aGUgbWVldGluZ3Mgb3ZlcmxhcD8gdHJ1ZQovLyBNaW5pbXVtIG51bWJlciBvZiByb29tcyByZXF1aXJlZDogMgo=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment