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?
- A. 17
- B. 23
- C. 20
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- How many index pairs i < j satisfy 3 divides a[i] + a[j] for a = [1, 2, 3, 4, 5, 6, 7]?
- How many ordered pairs (x, y) with 1 <= x, y <= 10 satisfy gcd(x, y) = 1?
- How many elements of [12, 19, 40, 7, 31, 22, 13, 8] have a decimal digit sum divisible by 4?
- How many perfect squares lie in the range [50, 250] inclusive?
- How many contiguous subarrays of [6, 10, 15, 4] have gcd exactly 1?
- A linked list holds 1..8 in order. Reverse the first group of 2 nodes, keep the next group of 2 as is, reverse the next, and so on. What…