Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA

Tasks are (deadline, duration): (3, 1), (2, 2), (4, 3), (5, 2), (1, 1). Tasks run one after another from time 0 without preemption, and a task finishes on time if its finish time is at most its deadline. What is the largest number of tasks that can all finish on time?

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

Correct answer: C. 2

Moore-Hodgson style: sort by deadline, add each task to the schedule, and when the running finish time passes a deadline, remove the longest task scheduled so far. Brute force over all subsets confirms the count.

More Coding Interview Problems questions

Exams that ask this topic