TRT
Sign in
mediumAdvancedcoding

Schedule the most meetings in one room

Solve interval scheduling with the earliest-end greedy, prove it, refute the alternatives, and handle the weighted variant.

TRT practice prompt — not a verified question from a named employer.

The Runtime Theory Team2 min read
Learn it firstScheduling and intervalsPro — members onlyTo fit the most non-overlapping intervals, always take the one that ends first. A 'greedy stays ahead' proof shows why, and the same rule solves a family of removal, arrow and partition problems.

A strong answer

A strong candidate frames Schedule the most meetings in one room around the exact memory layout, compiler semantics, and hardware execution model covered in Scheduling and intervals. Solve interval scheduling with the earliest-end greedy, prove it, refute the alternatives, and handle the weighted variant.

Given a set of intervals, such as meeting requests for one room, jobs for one machine or time slots for one antenna, choose as many as possible so that no two overlap. It is one of the cleanest examples of a greedy algorithm with a proof, and it is also a good lesson in how plausible greedy rules fail.

The rule that works is earliest end first: sort by end time, then scan, taking each interval that starts at or after the end of the last one taken. The trace above takes 1–3, skips 2–5, takes 4–7, skips 1–8 and 6–9, and takes 8–10. Sorting costs O(n log n) and the scan O(n).

In a production interview, always connect the specification rule to its concrete runtime consequence: state what lives on the stack versus the heap or static storage segment, how the compiler or operating system validates alignments, lifetimes, and error codes, and what happens under adversarial or boundary inputs (such as zero-length buffers, integer overflow, concurrent mutation, or partial I/O). Backing your explanation with a small trace of register/memory state transitions immediately separates senior systems engineers from candidates who only memorized syntax.

What the interviewer is listening for

  • Mastery of core invariant: Select the largest set of non-overlapping intervals by earliest end time.
  • Mastery of core invariant: Prove it with a greedy-stays-ahead argument, and refute the rules that fail.
  • Mastery of core invariant: Apply the rule to related problems, and recognize when weights require DP instead.
  • Hardware and ABI awareness: Explaining how sizes, alignments, calling conventions, or kernel boundaries behave on real 64-bit targets rather than relying on implementation-defined assumptions.
  • Defensive engineering: Naming the exact compiler flags (-Wall -Wextra -Werror), static analyzers, or runtime sanitizers (-fsanitize=address,undefined,thread) that verify correctness in CI.

Common mistakes

  • Explaining only surface syntax without tracing the underlying memory addresses, ownership lifetime, or kernel/user-space state transitions.
  • Assuming undefined behavior (such as signed overflow, uninitialized reads, strict-aliasing violations, or dangling pointers) will "just work" because it passed an unoptimized -O0 debug build.
  • Ignoring return codes, partial reads/writes, alignment padding, or cleanup paths when an allocation or syscall fails midway through a function.

This answer walks

Practice follow-ups

  1. 01Give a counterexample for choosing the shortest meeting first.
  2. 02What changes if meetings have different values?
  3. 03How many rooms do you need to hold all meetings?
  4. 04How do you find the minimum number of meetings to cancel?

Not started

Sign in to save your learning progress.

Sign in to save