N meetings in one room

Greedy Algorithms Scheduling and Interval Problems Medium

Given one meeting room and N meetings represented by two arrays, start and end, where start[i] represents the start time of the ith meeting and end[i] represents the end time of the ith meeting, determine the maximum number of meetings that can be accommodated in the meeting room if only one meeting can be held at a time.

Examples:

Input : Start = [1, 3, 0, 5, 8, 5] , End = [2, 4, 6, 7, 9, 9]

Output : 4

Explanation : The meetings that can be accommodated in meeting room are (1,2) , (3,4) , (5,7) , (8,9).

Input : Start = [10, 12, 20] , End = [20, 25, 30]

Output : 1

Explanation : Given the start and end time, only one meeting can be held in meeting room.

Input : Start = [1, 4, 6, 9] , End = [2, 5, 7, 12]

Constraints

  • 1 <= N <= 105
  • 0 <= start[i] < end[i] <= 105

Hints

  • Sort the meetings by their end time in ascending order. If two meetings have the same end time, sort by their start time.
  • Start with the earliest possible meeting. For each subsequent meeting, check if its start time is greater than or equal to the end time of the previously selected meeting.

Company Tags

IBM Seagate Technology Airbnb Philips Healthcare HCL Technologies ARM Flipkart Epic Systems Bain & Company Mastercard Swiggy Optum Roblox Unity Technologies JPMorgan Chase Rakuten KPMG Siemens Healthineers Epic Games Oracle Lyft Zomato Bungie Zynga McKinsey & Company Google Microsoft Amazon Meta Apple Netflix Adobe