Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA
Using each of the values 1, 2, 5, 9 and 20 at most once, which is the smallest positive integer that CANNOT be written as the sum of some subset?
- A. 5
- B. 3
- C. 4
- D. 8
Correct answer: C. 4
Subset sums of the sorted values extend contiguously as long as each new value is at most one more than the sum so far; the first gap shows the missing integer. Testing only single values or only prefix sums stops the search too early.
More Coding Interview Problems questions
- Half-open segments [1,4), [3,7), [6,10), [9,12), [2,5), [8,11) are given. Choose pairwise disjoint segments to maximise the total length…
- Closed intervals [0,3], [2,5], [4,8], [6,9], [8,12] are available. What is the minimum number of them needed so that every point of the…
- Closed intervals [1,6], [4,10], [5,5], [8,12], [2,3] are given. For the query points 5, 9 and 1, count how many intervals contain each…
- Piles of bananas [3, 6, 7, 11] must be eaten within H = 8 hours. Each hour you eat up to k bananas from one pile (a pile is finished in…
- Stalls at positions [1, 2, 4, 8, 9, 13] are available. Place 3 cows in distinct stalls so that the smallest distance between any two cows…
- Consider the bitmask DP that counts subsets of {1..n} with sum equal to S. For n = 4 and S = 5, what does the DP answer, counting the…