Data Structures & AlgorithmsHardProduct Company SDE · ICPC regional
Problem: A 0/1 knapsack has capacity 10 and items (weight, value): (5, 10), (4, 40), (6, 30), (3, 50). What is the maximum total value?
- A. 90
- B. 105
- C. 150
- D. 130
Correct answer: A. 90
The DP over capacity finds (4, 40) + (3, 50) = 90 with weight 7; no remaining item fits in 3. Fractional knapsack would add half of (6, 30) for 105, reusing (3, 50) three times (unbounded) gives 150, and 130 takes every item while ignoring the capacity.
More Coding Interview Problems questions
- Problem: The longest bitonic subsequence (first strictly increasing, then strictly decreasing, either part may be empty) of [1, 11, 2, 10…
- Problem: Find the minimum path sum from the top to the bottom of the triangle [[2], [3, 4], [6, 5, 7], [4, 1, 8, 3]], moving to an…
- Problem: The message "2261" is decoded by mapping 1→A, ..., 26→Z. Each decoding splits the digits into groups of one or two digits, each…
- Problem: 23 people stand in a circle numbered 1 to 23. Starting at person 1, every second person is eliminated (counting around the…
- Problem: Eight cards labelled 1 to 8 are in a row. A perfect out-shuffle splits the deck into two equal halves (1–4 and 5–8) and…
- Problem: Lamps 1 to 20 are all off. For each pass i = 1 to 20, every lamp whose number is a multiple of i is toggled. How many lamps are…