Data Structures & AlgorithmsVery hardLeetCode-style · GATE CS

Events are given as (start day, end day) inclusive: [(1, 2), (2, 3), (3, 4), (1, 2), (3, 5)]. You may attend at most one event per day. What is the maximum number of events you can attend?

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

Correct answer: B. 5

Sweep the days in order: at each day add events that have started, drop ones already ended, and attend the one that ends earliest (min-heap). Attending events in order of start time can waste a day on a long event that blocks two short ones.

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

Exams that ask this topic