Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA
Arrays A = [2, 3, 5, 7, 4] and B = [6, 10, 1, 3, 8]. How many pairs (x in A, y in B) satisfy x * y = 24?
- A. 4
- B. 1
- C. 11
- D. 2
Correct answer: D. 2
For each x, the required partner is P / x when it is an integer; a hash set of B makes each lookup O(1). Checking the product bound instead of equality counts a larger set of pairs.
More Coding Interview Problems questions
- Weighted intervals (start, end, value): (0,5,4), (3,9,6), (6,10,3), (9,12,5). Choose two intervals that do not overlap (touching at an…
- Array a = [-2, 5, -1, 4, -3, 6]. How many contiguous subarrays have a sum strictly between 0 and 10?
- Sorted array [2, 3, 7, 9, 12, 15, 18]. How many index pairs i < j have a difference srt[j] - srt[i] in the range (3, 8], i.e. greater than…
- How many integers x with 1 <= x <= 30 have a binary representation with no two adjacent 1-bits?
- From the ten numbers [3, 8, 12, 5, 7, 10, 1, 4, 9, 6], how many 3-element subsets have a sum divisible by 5?
- A car starts at position 0 with 10 litres of fuel. It must reach position 40; it uses one litre per unit of distance. Gas stations at…