Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA
Sorted arrays A = [1, 4, 6, 9] and B = [2, 3, 7, 10]. How many pairs (x from A, y from B) have 8 <= x + y <= 12?
- A. 7
- B. 8
- C. 6
- D. 4
Correct answer: A. 7
For each x, the valid y values lie in a contiguous block of sorted B, found with two pointers or binary search; counting the block bounds gives the answer. Using open bounds drops sums exactly equal to 8 or 12.
More Coding Interview Problems questions
- Array a = [1, 2, 3, 1, 2, 3, 1]. How many contiguous subarrays of length at least 2 have the sum of the elements at even offsets (0, 2, 4…
- Array [1, 2, 3, 4, 5, 6, 7, 0]. How many index pairs i < j satisfy (a[i] OR a[j]) = 7?
- Coins have values 1, 3, 9, 27, 81, ... (powers of three, unlimited supply). What is the minimum number of coins needed to pay exactly 41?
- Array [5, 1, 4, 6, 2, 8, 3, 7]. What is the length of the longest contiguous subarray whose maximum minus minimum is at most 3?
- Array a = [3, 4, 7, 1, 6, 2, 5, 8]. How many contiguous subarrays have a sum that is divisible by 7?
- A 2 x 7 board is to be covered by 1 x 2 dominoes (each may be placed horizontally or vertically). How many tilings are there? Use the…