Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: The fractional knapsack has capacity 50 and items (value, weight): (60, 10), (100, 20), (120, 30). Items may be taken fractionally. What is the maximum value, rounded down to an integer?

  1. A. 220
  2. B. 160
  3. C. 240
  4. D. 280

Correct answer: C. 240

Sort by value/weight (6, 5, 4): take items 1 and 2 whole (160, weight 30) and 20/30 of item 3 (80), for 240. The 0/1 knapsack optimum is 220, taking only whole items greedily stops at 160, and 280 ignores the capacity.

More Coding Interview Problems questions

Exams that ask this topic