Data Structures & AlgorithmsHardProduct Company SDE · Amazon OA

Problem: A set of jobs has deadlines and profits: (deadline 1, profit 20), (deadline 2, profit 40), (deadline 2, profit 30), (deadline 3, profit 10). Each job takes one unit and must finish by its deadline. How many jobs can be scheduled in the best selection?

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

Correct answer: C. 3

Greedy by profit: 40 takes slot 2, 30 takes slot 1 (deadline 2 with slot 2 taken), 20 cannot fit slot 1 (taken) so it is dropped, and 10 takes slot 3. That gives three jobs scheduled.

More Coding Interview Problems questions

Exams that ask this topic