Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA
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?
- A. 2
- B. 15
- C. 12
- D. 1
Correct answer: D. 1
Put B into a set and look up 22 - x for each x in A; each hit is one pair. Counting pairs with sum at most 22 counts far more, which is a different question.
More Coding Interview Problems questions
- 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…
- Problem: Count inversions in [2, 4, 1, 3, 5] with a Fenwick tree over the values. python def inv(a): n = max(a) t = [0] (n + 1) def…