KatInterview

Maximum Non-Overlapping Meetings in a Workday

Greedy & IntervalsAuto-graded · 17 test cases
MediumAuto-gradedGreedy & Intervalsgreedyintervalsstrings

Last updated

Tests greedy interval scheduling and string parsing: convert "Name: HH:MM-HH:MM" strings into time intervals, then find the largest set of compatible meetings.

Daily Meeting Planner

You are building a personal scheduling assistant. Given a list of meeting request strings, your tool must figure out how many meetings a person can actually attend in a single day — no two meetings may run at the same time.

Input Format

Each meeting is described by a string in this exact format:

"<Title>: <HH:MM>-<HH:MM>"
  • <Title> is the meeting name (may contain spaces, but never the substring ": ").
  • Times use 24-hour notation, e.g. "08:30" or "17:45".
  • The start time is always strictly before the end time.

Task

Implement optimize_schedule(meetings) that accepts this raw list of strings and returns a single integer: the maximum number of meetings that can be attended without any two overlapping.

Overlap rule: two meetings are considered compatible — not overlapping — when one ends at the exact minute the other begins. For example, a meeting ending at 10:00 and one starting at 10:00 may both be attended.

Tie-breaking rule: when two meetings share the same end time, prefer the shorter one (i.e., the one that starts later). This tie-break does not affect the count, but it must be applied consistently to match expected outputs.

Constraints

  • 0 <= len(meetings) <= 1000
  • All times fall within 00:00–23:59.
  • Every meeting satisfies end > start (no zero-length meetings).
  • Input strings are well-formed; no validation is required.

Examples

Example 1

Input: optimize_schedule(['A: 09:00-10:00', 'B: 09:30-10:30', 'C: 10:00-11:00'])

Output: 2

Hints

Hint 1

Start by converting each time string into a plain integer (minutes since midnight). That turns string comparison into simple arithmetic.

Hint 2

Once you have numeric intervals, think about which meeting to commit to first. Sorting by end time is the classical greedy strategy for maximizing the count of non-overlapping intervals — ask yourself why picking the earliest-finishing meeting is always at least as good as any other choice.

Hint 3

Be careful about the boundary condition: does 'non-overlapping' mean start > last_end or start >= last_end? The example in the problem tells you which one is correct.