Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA
Sorted array a = [2, 3, 5, 6, 8, 10]. How many DISTINCT values appear among the sums a[i] + a[j] over pairs i < j?
- A. 12
- B. 15
- C. 14
- D. 11
Correct answer: A. 12
There are 15 index pairs, but some sums coincide, so the answer is the number of distinct values among them. Put every pairwise sum into a set and take its size; counting index pairs gives 15 and ignores repeated sums.
More Coding Interview Problems questions
- Sorted array a = [1, 2, 4, 5, 6, 9, 10, 11]. How many elements does the largest contiguous block of this array have if its largest element…
- How many permutations (p1, ..., p5) of the numbers 1 to 5 satisfy pi <= i + 1 for every position i? Use a bitmask DP over the set of…
- Choose any subset (empty allowed) of {1, 2, 3, 4, 5}. How many subsets have bitwise OR equal to 7?
- How many binary strings of length 8 contain no three consecutive 1s?
- Array [5, 2, 8, 1, 4, 6, 3]. How many index pairs i < j have a[i] AND a[j] = 0 (no common set bit)?
- What is the minimum number of single-bit flips needed to change the 8-bit number 13 into the 8-bit number 22?