Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Four groups are G1 = {1, 4}, G2 = {2, 9}, G3 = {3, 7} and G4 = {5, 6}. Choosing exactly one element from each group, how many choices sum to 14?
- A. 2
- B. 1
- C. 0
- D. 3
Correct answer: B. 1
Combine groups one and two into all 4 sums, combine groups three and four into all 4 sums, and count complementary pairs using a counter. The pair count is over choices, so repeated sums must be counted with multiplicity.
More Coding Interview Problems questions
- 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…
- 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…