Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
With coins of values 1, 3 and 4 (each usable any number of times), in how many ways (order does not matter) can you make the amount 6?
- A. 6
- B. 3
- C. 4
- D. 5
Correct answer: C. 4
Coin-change counting: iterate coins in the outer loop so each multiset is counted once. Looping amounts in the outer loop counts orderings instead, which is the classic mistake.
More Coding Interview Problems questions
- What is the length of the longest run of equal consecutive values in [4, 4, 1, 2, 2, 2, 5, 1]?
- Problem: Two sorted arrays of sizes m and n are merged in O(m + n) time with two pointers. What is the complexity of finding the median of…
- Array a = [3, 2, 5, 1, 4, 6, 2, 7]. Consider all contiguous subarrays and count those whose sum is a power of two from the set {1, 2, 4…
- Array a = [4, 7, 1, 8, 3, 6, 5, 2]. What is the largest sum of a contiguous subarray that contains exactly two odd numbers?
- Array a = [2, 5, 1, 6, 3, 8, 4]. How many ordered pairs of distinct positions (i, j) satisfy a[j] >= 2 a[i]?
- From the values [4, 9, 1, 12, 7, 3, 10, 6], keep as many as possible so that in the kept set the maximum is at most twice the minimum. How…