Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA
Four tasks each have (time, value): (3,2), (2,5), (4,4), (5,3). Choose any subset of tasks with total time at most 9 to maximise total value. What is that maximum value?
- A. 14
- B. 9
- C. 11
- D. 20
Correct answer: C. 11
Enumerating all 16 subsets, the best within time 9 is (3,2) + (2,5) + (4,4): time 9, value 11. Requiring time < 9 gives 9, taking all four tasks (time 14) breaks the limit and gives 14, and reusing the (2,5) task four times as in unbounded knapsack gives 20.
More Coding Interview Problems questions
- In how many ways can a set of 6 distinct people be partitioned into groups so that every group has an even number of people (groups are…
- From the values [3, 5, 6, 7, 10], choose any non-empty subset and XOR its elements together. What is the largest value that can be obtained?
- Four groups are G1 = {1, 4}, G2 = {2, 9}, G3 = {3, 7} and G4 = {5, 6}. Choosing exactly one element from each group, how many choices sum…
- Using each of the values 1, 2, 5, 9 and 20 at most once, which is the smallest positive integer that CANNOT be written as the sum of some…
- Half-open segments [1,4), [3,7), [6,10), [9,12), [2,5), [8,11) are given. Choose pairwise disjoint segments to maximise the total length…
- Closed intervals [0,3], [2,5], [4,8], [6,9], [8,12] are available. What is the minimum number of them needed so that every point of the…