Data Structures & AlgorithmsModerateCodeforces Div2 B · DP warm-up
Problem: Coins of values {1, 5, 6, 9} are available, unlimited copies each. What is the minimum number of coins needed to make exactly 11?
- A. 2
- B. 3
- C. 4
- D. 11
Correct answer: A. 2
Greedy gives 9 + 1 + 1 = 3 coins, but 5 + 6 = 11 uses only 2 coins. Greedy fails for this coin system, so the optimum needs a DP over amounts.
More Coding Interview Problems questions
- Problem: In the O(n log n) longest increasing subsequence algorithm, the array tails[k] is maintained over the input. What does tails[k]…
- Problem: A dynamic array doubles its capacity whenever it is full and copies all elements. Which statement about n pushes is correct?
- Problem: How many ways are there to tile a 2 x 10 board completely with 2 x 1 dominoes (placed horizontally or vertically)?
- Array a = [1, -1, 2, 3, -2, 4, -3, 1]. How many contiguous non-empty subarrays have sum exactly 3? Solve it with running prefix sums and a…
- For a = [3, 4, -7, 2, -2, 5, -5, 1, 6], what is the length of the longest contiguous subarray whose elements sum to 0?
- Array a = [-2, 3, -4, 6, -1, 2]. How many non-empty subarrays have a sum divisible by 5? Count prefix sums by their remainder, normalised…