Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA
A subset-sum question has n = 40 values. Splitting them into two halves of 20, how many subset sums must be enumerated for ONE half?
- A. 1048576
- B. 1099511627776
- C. 549755813888
- D. 2097152
Correct answer: A. 1048576
Each half has 20 elements and therefore 2^20 = 1,048,576 subsets. Enumerating all 2^40 subsets is what meet-in-the-middle avoids; the two sorted half-lists then combine with a two-pointer pass.
More Coding Interview Problems questions
- Closed intervals [1,3], [3,5], [2,4], [5,7], [6,8] are given. Two intervals conflict if they share any point, endpoints included. What is…
- Meetings are the half-open intervals [0,30), [5,10), [15,20), [10,15), [20,25); a room can host a new meeting starting exactly when…
- Balloons are closed horizontal intervals [10,16], [2,8], [1,6], [7,12]. One vertical arrow at x bursts every balloon whose interval…
- Half-open intervals [1,2), [2,3), [3,4) and [1,3) are given. What is the minimum number of intervals that must be removed so that the…
- Jobs are (start, end, profit) triples: (1,4,5), (3,5,1), (0,6,8), (4,7,4), (3,8,6), (5,9,3), (6,10,2), (8,11,4). One machine can run a set…
- Intervals [0,4], [3,7], [6,10], [2,6], [9,12], [1,3] are available. What is the minimum number of them needed to cover the whole segment…