PPractick

DSA interview question

N Meetings in One Room

Medium · Algorithms · Topics: greedy, sorting

The problem

A single conference room has n meeting requests, each with a start and an end time. Only one meeting can use the room at a time, and a meeting can start only strictly after the previous one ends (the room needs a moment to reset). What's the maximum number of meetings that can be held? This is interval scheduling, and the classic greedy is to always pick the meeting that finishes earliest among those that fit, because finishing early leaves the most room for the rest.

Example: start [1, 3, 0, 5, 8, 5], end [2, 4, 6, 7, 9, 9] → 4.

Function signature

int maxMeetings(const vector<int>& start, const vector<int>& end);

Test cases

Input (start, end)OutputExplanation
([1, 3, 0, 5, 8, 5], [2, 4, 6, 7, 9, 9])4(1,2), (3,4), (5,7), (8,9)
([10, 12, 20], [20, 25, 30])120 is not strictly after 20
([1, 2], [1, 2])2Instant meetings
([1, 1, 1], [2, 2, 2])1All overlap
([1], [5])1

(Confirm: a meeting may start only when its start is strictly greater than the previous meeting's end.)

How interviewers phrase it

Clarifying questions to ask

  1. Can a meeting start at the exact time the previous one ends? (Not here: strictly after.)
  2. Should I return the count or the chosen meetings?
  3. How are ties in end time handled? (Any order works for the count.)

Follow-ups to expect

  1. "Why the earliest end time?"
  2. "Why not the earliest start or the shortest meeting?"
  3. "How do you output the meeting indices?"
  4. "The minimum number of rooms for all meetings?"
  5. "Complexity?"

Practise questions like this with a real engineer

On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.

Book a free mock interview

Related questions

All 474 dsa interview questions

DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in