Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA

What is the maximum number of pairwise non-overlapping intervals (an interval [s, f) may touch the next one at f = s) chosen from [(1,4),(3,5),(0,6),(5,7),(3,9),(5,9),(6,10),(8,11),(8,12),(2,14),(12,16)]?

  1. A. 5
  2. B. 3
  3. C. 4
  4. D. 2

Correct answer: C. 4

Greedy by earliest finish time is optimal by an exchange argument: replacing the first chosen interval by the one that finishes earliest never hurts. Sorting by start time instead is a known failure.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic