Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA
Coins have values 1, 3, 9, 27, 81, ... (powers of three, unlimited supply). What is the minimum number of coins needed to pay exactly 41?
- A. 6
- B. 2
- C. 4
- D. 5
Correct answer: D. 5
41 written in base 3 is 1112, and the minimum number of powers of three summing to 41 equals its digit sum, 1 + 1 + 1 + 2 = 5. Taking the largest coin first is optimal for these coin values.
More Coding Interview Problems questions
- Array [5, 1, 4, 6, 2, 8, 3, 7]. What is the length of the longest contiguous subarray whose maximum minus minimum is at most 3?
- Array a = [3, 4, 7, 1, 6, 2, 5, 8]. How many contiguous subarrays have a sum that is divisible by 7?
- A 2 x 7 board is to be covered by 1 x 2 dominoes (each may be placed horizontally or vertically). How many tilings are there? Use the…
- Arrays A = [2, 3, 5, 7, 4] and B = [6, 10, 1, 3, 8]. How many pairs (x in A, y in B) satisfy x y = 24?
- Weighted intervals (start, end, value): (0,5,4), (3,9,6), (6,10,3), (9,12,5). Choose two intervals that do not overlap (touching at an…
- Array a = [-2, 5, -1, 4, -3, 6]. How many contiguous subarrays have a sum strictly between 0 and 10?