Data Structures & AlgorithmsHardTCS NQT · GATE CS
Coins of value 2, 3 and 7 are available in unlimited supply. What is the minimum number of coins needed to make exactly 20?
- A. 4
- B. 5
- C. 3
- D. 6
Correct answer: A. 4
DP over amounts: dp[v] = 1 + min over coins c ≤ v of dp[v − c]. The minimum is four coins (7 + 7 + 3 + 3). A DP over amounts, dp[v] = 1 + min dp[v − c], finds this exactly, whereas a rule that fixes the number of 7s first (for example 20 // 7 = 2 and then 6 more) can miss the cheapest split.
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
- In how many ways can you choose 4 distinct numbers from 1 to 6 and list them in increasing order? (Each choice gives exactly one…
- Choose a subsequence of [4, 7, 2, 9, 5, 6, 1] with no two chosen positions adjacent, such that its total is ODD. What is the largest such…
- Count the pairs of positions (i < j) in [3, 4, 7, 2, 9, 6] such that a[i] + a[j] is odd and i + j is even.
- Choose two positions i < j with j − i ≥ 3 in [5, -4, 3, 8, -6, 2, 7]. What is the largest possible product a[i] · a[j]?
- What is the minimum number of characters you must delete from "aaabbbbcccccdd" so that no three equal letters are consecutive?
- How many non-empty subsets of {1, 2, ..., 8} have a sum divisible by 4?