Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 C
Coins of values 1, 4, 9 and 16 are available in unlimited supply. What is the minimum number of coins that makes exactly 27?
- A. 3
- B. 4
- C. 2
- D. 5
Correct answer: A. 3
Unbounded coin-change DP: dp[v] = 1 + min dp[v − c] over the four coins. Greedy largest-first is not guaranteed here: it uses 16 + 9 + 1 + 1 = 4 coins while 9 + 9 + 9 uses 3.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the maximum sum of a contiguous subarray of [4, -3, 5, 2, -7, 6, 1, 3] whose length is ODD?
- How many contiguous subarrays of [2, 3, 5, 4, 7, 6, 9] contain EXACTLY two odd numbers?
- Among the windows of exactly 3 consecutive elements of [5, 2, 9, 1, 7, 3, 8, 4], what is the smallest window sum that is at least 15?
- How many triples (a, b, c) with a < b < c taken from the set [1, 2, 3, 4, 5, 6, 8, 10, 12] satisfy a + b = c?
- How many strings of length 5 over the alphabet {a, b, c} do NOT contain the substring "abc"?
- A 2 × 5 grid has obstacles at (row, column) positions [(0, 2), (1, 3)] (rows 0 and 1, columns 0 to 4). Starting at (0,0), you move one…