Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA

Four jobs have processing times [6, 3, 5, 2]. They run one at a time in some order, and job at position i (1-based) incurs cost i times its time. What is the minimum total weighted completion cost, sum of position times time?

  1. A. 36
  2. B. 31
  3. C. 32
  4. D. 33

Correct answer: D. 33

The minimum is attained by running jobs in non-decreasing order of processing time (shortest processing time first), an exchange argument on adjacent pairs. Running in input order gives a larger cost.

More Coding Interview Problems questions

Exams that ask this topic