Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 C

Unit-time tasks have deadlines [1, 2, 2, 3, 3, 3, 5, 6] (a task must finish by its deadline, and only one task runs at a time from time 1). What is the maximum number of tasks that can be completed on time?

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

Correct answer: D. 5

Sort the deadlines and keep a count of tasks taken so far; take a task only when it can still finish by its deadline. Counting the tasks with a valid deadline ignores that too many share the same early slot.

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

Exams that ask this topic