Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA
Set A = {1, 2, 4, 7} and set B = {3, 5, 6, 8}. Choose two different elements from A and two different elements from B. How many choices give equal sums for the two pairs?
- A. 6
- B. 3
- C. 5
- D. 4
Correct answer: D. 4
Count the 2-element sums of A and of B with multiplicity, then multiply the counts for each equal sum. Counting distinct common sums misses the multiplicities.
More Coding Interview Problems questions
- Half-open intervals [0,2), [1,3), [2,4), [3,5), [4,6). What is the minimum number of intervals to remove so the remaining intervals are…
- Array a = [2, 3, 5, 1, 4, 5, 2, 3]. How many contiguous subarrays have an even length and a sum divisible by 5?
- In the binary string "1101001100", find the length of the longest substring that has equally many 0s and 1s and whose length is a multiple…
- Values [1, 9, 4, 12, 7, 15, 3]. How many unordered pairs of distinct positions have an absolute difference of at least 5?
- How many subsets of {1, 2, ..., 12} have a sum of exactly 20?
- How many integers x with 1 <= x <= 200 have an odd number of 1-bits in their binary representation?