Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

Five jobs with durations [4, 3, 7, 1, 2] run one at a time on one machine. What is the minimum possible sum of waiting times (the time each job waits before it starts), over all orders?

  1. A. 17
  2. B. 23
  3. C. 20
  4. D. 21

Correct answer: C. 20

Shortest-job-first minimises the sum of start times by an exchange argument: swapping adjacent jobs with a longer job first never helps. Here the order 1, 2, 3, 4, 7 gives waits 0,1,3,6,10 totalling 20.

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

Exams that ask this topic