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?
- A. 36
- B. 31
- C. 32
- 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
- For the values [2, 5, 3, 8, 1, 6], how many values give remainder 1 or 2 when divided by 3 (counted once for each value)?
- Array [4, 4, 7, 1, 7, 2]. How many index pairs i < j have equal values a[i] = a[j]?
- Array [3, 7, 2, 9, 4]. How many contiguous subarrays sum to exactly 9?
- Problem: Fresh oranges (1) rot their neighbours (4-directional) one minute at a time; 0 is empty and 2 is rotten. How many minutes until…
- Problem: How many distinct palindromic substrings does 'aaaa' have? Run the code. python s = 'aaaa' print(len({s[i:j] for i in…
- Problem: Count the start indices i where a permutation of 'abc' begins in s = 'cbaebabacd' (the anagram-window problem). Run the code…