N meetings in one room

Asked atFactSet Research Systems Inc.
1Give yourself 5 minutes
2Answer out loud, not in your head
3Then compare with the answer below

The problem

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.

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]

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

cpp

class Solution{
    public:
    int maxMeetings(vector<int>& start, vector<int>& end){
        //your code goes here
    }
};

java

class Solution {
    public int maxMeetings(int[] start, int[] end) {
       //your code goes here
    }
}

python

class Solution:
    def maxMeetings(self, start, end):
        #your code goes here

javascript

class Solution {
    maxMeetings(start, end) {
        //your code goes here
    }
}

csharp

public class Solution
{
    public int maxMeetings(List<int> start, List<int> end)
    {
        //your code goes here
    }
}

go

func maxMeetings(start []int, end []int) int {
	//your code goes here
}
Stuck? Show a way to structure it+
  1. 01Sort meetings by end time with stable tie handling
  2. 02Select the first meeting
  3. 03Select each compatible later meeting
  4. 04Return count or original indices as required

Reference answer

Then expect these follow-ups

  • Why is earliest finish greedy optimal?

    Tests: correctness reasoning

  • How would weighted meetings change the solution?

    Tests: constraint adaptation

Free to read · better with Enzo

Practice this out loud with Enzo

Enzo runs it as a mock interview, pushes back with follow-ups, and grades you on the rubric.

Next question