Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA
Arrays A = [1, 2], B = [-2, -1], C = [-1, 2] and D = [0, 2] each have two entries. How many index quadruples (i, j, k, l) satisfy A[i] + B[j] + C[k] + D[l] = 0? Use a meet-in-the-middle count of pair sums.
- A. 1
- B. 4
- C. 2
- D. 6
Correct answer: C. 2
Put the sums A+B into a counter and, for each pair from C and D, look up the negated sum and add its multiplicity. The count is over index quadruples (2); collecting distinct sum values gives only 1.
More Coding Interview Problems questions
- How many subsets of {1, 2, ..., 10} have a sum of exactly 10? The single-element subset {10} counts as one of them.
- 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?
- 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…