Data Structures & AlgorithmsModerateTCS NQT · Infosys
Problem: Using US coin denominations 1, 5, 10, 25, what is the minimum number of coins needed to make 63 (greedy works for these denominations)?
- A. 3
- B. 7
- C. 15
- D. 6
Correct answer: D. 6
Greedy: 25 + 25 + 10 + 1 + 1 + 1 = 63, six coins, which is optimal for this canonical set. 3 counts the denominations used, using two nickels instead of a dime gives 7, and 2 quarters + 13 pennies gives 15.
More Coding Interview Problems questions
- Problem: Count the walks of length 3 on the path graph P4 (vertices 1–4, edges 1-2, 2-3, 3-4) that start and end at the same vertex. Walks…
- Problem: The array [2, 7, 4, 1, 8, 1] is examined by a sweep: for each index i, the value a[i] is compared with the minimum of the…
- Problem: Starting with the stack [1] (top is the rightmost element), the operations are: push 2, push 3, pop, push 4, push 5, pop, pop…
- Problem: A bank processes queued withdrawals of 40, 25, 60, 15, 30 from a balance of 100. Each withdrawal is processed only if the current…
- Problem: The Z-array of "aaabaab" is computed (z[0] is the full length by convention). What is the sum of z[1] through z[6]?
- Problem: The string "aaaa" has how many distinct palindromic substrings (counting each distinct string once, of any length ≥ 1)?