Data Structures & AlgorithmsModerateTCS NQT · Accenture
Problem: Coins of denominations 5, 12 and 20 are available in unlimited supply. What is the minimum number of coins needed to make exactly 63?
- A. 5
- B. 7
- C. No combination works
- D. 4
Correct answer: B. 7
Checking every count of 20s and 12s, 63 = 12 × 4 + 5 × 3 is the only representation, so 7 coins. Greedy 20, 20, 20 is stuck with 3 and wrongly concludes that no combination works, 20 + 20 + 12 + 5 + 5 = 62 is one short (5 coins), and 20 + 20 + 12 + 12 = 64 overshoots (4 coins).
More Coding Interview Problems questions
- Problem: The list [25, 14, 9, 31, 7, 18, 3, 12] is turned into a min-heap in place with heapify (standard bottom-up sift-down, 0-indexed)…
- Problem: The sorted array [2, 4, 4, 4, 7, 9, 9, 12] is searched with bisectleft and bisectright. What is bisectright(a, 4) − bisectleft(a…
- Problem: Compute (7^2026 + 11^2026) mod 1000, where ^ is exponentiation.
- Problem: Maximum number of non-overlapping meetings that can be held in one room, where a meeting is an interval [start, end) and two…
- Problem: How many contiguous subarrays of [3, -1, 4, -2, 5, -6, 2, 1] have sum at most 6 when the sum is computed over all non-empty…
- Problem: Longest substring without repeating characters of "pwwkewabcdbbxq". What is its length?