Data Structures & AlgorithmsHardICPC regional · TCS NQT Digital
Problem: A bag holds coins of values 1, 4 and 9. You must pay exactly 30 using as few coins as possible. What is the minimum number of coins?
- A. 6
- B. 4
- C. 7
- D. 5
Correct answer: D. 5
Unbounded coin DP finds the minimum number of coins. Taking the largest coin first gives 9+9+9+1+1+1 = 30 with six coins, but a better combination exists.
More Coding Interview Problems questions
- Problem: The 0/1 matrix [[1,0,1],[1,1,0],[0,1,1]] is considered. A 'plus' is a centre cell with value 1 whose four neighbours (up, down…
- Problem: Two heaps are maintained over the stream 5, 15, 1, 3, 8, 7, 9, 10, 6, 11 to report the median after each element (lower median…
- Problem: The string "abcabcbb" is scanned and for each position the length of the longest run of distinct characters starting at that…
- Problem: Dijkstra's algorithm in an undirected graph with edges 0-1 (2), 1-2 (2), 0-2 (5), 2-3 (1), 1-3 (6). How many vertices have a…
- Problem: The string "xyyxzzyx" is examined for palindromic substrings of length 4 or more. How many such palindromic substrings are there…
- Problem: A binary string is "good" if it has no two consecutive zeros. How many good strings of length 7 begin with 1 and end with 1?