Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA
How many subsets (including the empty subset) of the values [2, 3, 5, 7, 11, 13, 4, 6] have a sum between 10 and 20 inclusive?
- A. 71
- B. 62
- C. 67
- D. 57
Correct answer: C. 67
Meet in the middle: enumerate sums of each half, sort one list, and count with two binary searches per value to get the number in the range. Subsets whose sum is exactly 20 must be included, which the strict upper bound drops.
More Coding Interview Problems questions
- The values [7, 4, 9, 2, 6, 5] are distributed among two groups (each value goes to exactly one group, any group may be empty). What is the…
- Closed intervals [1,3], [2,6], [3,5], [4,8], [7,9], [9,11], [10,12]. Two intervals conflict if they share any point, endpoints included…
- Half-open intervals [0,4), [1,3), [2,6), [5,7), [6,9), [8,10). What is the minimum number of integer points such that every interval…
- Tasks are (deadline, duration): (3, 1), (2, 2), (4, 3), (5, 2), (1, 1). Tasks run one after another from time 0 without preemption, and a…
- Split the array [7, 2, 5, 10, 8, 4, 6] into 3 non-empty contiguous parts so that the largest part sum is as small as possible. What is…
- Sorted arrays A = [1, 4, 6, 9] and B = [2, 3, 7, 10]. How many pairs (x from A, y from B) have 8 <= x + y <= 12?