Data Structures & AlgorithmsHardGoldman Sachs OA · LeetCode medium-hard
Fractional knapsack, capacity 15 (items can be split). Items (weight, value): (3, 15), (7, 15), (4, 15), (5, 8), (3, 11). Using the greedy value/weight-ratio algorithm, what is the maximum total value (rounded to 2 decimals)?
- A. 50.71
- B. 49
- C. 51.71
- D. 52.71
Correct answer: C. 51.71
Sorting items by value/weight ratio and greedily taking as much as possible of the best ratio first (splitting the last item to exactly fill the capacity) is optimal for the fractional version, giving 51.71. This greedy choice is only optimal because items can be split; the 0/1 version of the same items would instead give 49.
More Coding Interview Problems questions
- Merging overlapping intervals (sort by start, merge when the next interval's start is ≤ the current merged interval's end — touching…
- What is the length of the longest common subsequence of "DBDDDDEA" and "AADAADAB"?
- Using the merge-sort inversion-count technique (count, during each merge step, how many left-half elements are greater than the current…
- Using the merge-sort inversion-count technique (count, during each merge step, how many left-half elements are greater than the current…
- Problem: 6 servers are joined by cables one at a time. Count the connected groups at the end and how many cables were redundant (joined…
- What is the length of the longest common subsequence of "AABEDAA" and "DEDAEECD"?