Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS
With coins of denominations 1, 5, 6 and 9, what is the minimum number of coins needed to make the amount 15?
- A. 3
- B. 1
- C. 7
- D. 2
Correct answer: D. 2
A DP over amounts is needed: greedy takes 9 + 6 for two coins, which is optimal here, but the trap is the greedy that starts with the largest coin and ends with ones. Compare the DP value to see which is minimal.
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
- Including the empty prefix (sum 0), how many of the prefix sums of [3, 1, 4, 2, 6, 5, 3, 1] are divisible by 4?
- How many distinct residues modulo 7 are produced by x y for x and y ranging over {2, 3, 4} (all ordered pairs, including x = y)?
- How many pairs i < j in [4, 1, 5, 2, 3] satisfy a[i] > a[j] and every element strictly between them is at most a[i]?
- How many ordered pairs (i, j) with i != j in [1, 3, 2, 6, 4] have a[i] AND a[j] = a[i], meaning the bits of a[i] are a subset of the bits…
- What is the length of the longest contiguous subarray of [1, 2, 1, 3, 4, 3, 5] in which at most one element is a repeat of an earlier…
- How many trailing zeros does 50! (50 factorial) have in decimal?