Data Structures & AlgorithmsModerateTCS NQT · Infosys
What is the minimum number of coins needed to make an amount of 18 using unlimited coins of denominations {1, 6, 10}?
- A. 4
- B. 3
- C. 2
- D. 5
Correct answer: B. 3
Greedy picks 10 + 6 + 1 + 1 = 4 coins, but three coins of 6 give 18 exactly. This denomination set is not canonical, so DP (or checking alternatives) is required.
More Coding Interview Problems questions
- The array is [3, 3, 4, 4, 5, 1, 2, 2, 6, 3, 7]. What is the length of its longest non-decreasing (not strictly increasing) subsequence?
- For the circular array [5, -3, 5, -2, 6, -8, 4], what is the maximum sum of a non-empty contiguous subarray when the subarray is allowed…
- A robot moves only right or down from the top-left to the bottom-right cell of this 6×6 grid, where # is a blocked cell and . is free…
- For the array [4, 5, 0, -2, -3, 1, 7, -9, 6] and k = 5, how many non-empty contiguous subarrays have a sum divisible by k?
- How many pairs of indices (i, j) with i < j satisfy a[i] > 2·a[j] in a = [5, 2, 6, 1, 7, 3, 9, 2, 4]?
- A walker moves from (0,0) to (4,4) on lattice points using steps (1,0), (0,1) and (1,1). The point (2,2) is forbidden. How many different…