Data Structures & AlgorithmsHardGATE CS · TCS NQT

Activities (start, finish) are [(1, 4), (3, 5), (0, 6), (5, 7), (3, 9), (5, 9), (6, 10), (8, 11), (8, 12), (2, 14), (12, 16)]. Two activities conflict if their time ranges overlap or touch (an activity may start only strictly after the previous one finishes). What is the maximum number of activities one person can attend?

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

Correct answer: A. 4

Sort by finish time and greedily take each activity that starts after the last finish. Sorting by start time, or by shortest duration, looks reasonable but can block two or more later activities for one long or early one.

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

Exams that ask this topic