Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA
From the values [5, 12, 7, 3, 9, 14, 2, 8], what is the minimum number of values you must choose so that their sum is at least 25? Meet in the middle can find the best sums of each half and combine them.
- A. 3
- B. 1
- C. 2
- D. 4
Correct answer: C. 2
Check subsets by size, using meet in the middle over the halves to find the best sum for each size. The smallest size whose best sum reaches 25 is 2, since 14 + 12 = 26 is the strongest pair.
More Coding Interview Problems questions
- Arrays A = [3, 7, 11, 15, 20] and B = [2, 6, 9, 13, 18] each hold distinct values. How many pairs (x in A, y in B) satisfy x + y = 22?
- Half-open intervals [1,6), [2,4), [3,8), [5,7), [6,9), [7,10) are given. What is the maximum number of intervals that contain a common…
- Trains (arrival, departure) in minutes are (900,930), (940,1200), (950,1120), (1100,1130), (1500,1800), (1130,1140). A platform holds one…
- The half-open intervals [0,3), [2,5), [4,8) and [7,9) are given. What is the total length of their union (the number of unit-length cells…
- Intervals [1,6), [2,4), [3,8), [5,7), [6,9), [7,10) are given. How many unordered pairs of these intervals overlap (share at least one…
- Problem: Sum the minimum of every non-empty subarray of [3, 1, 2, 4] by brute force. python a = [3, 1, 2, 4] print(sum(min(a[i:j + 1]) for…