Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Sorted positive array [1, 3, 4, 6, 9, 12]. How many index pairs i < j have a[i] * a[j] >= 18?
- A. 12
- B. 8
- C. 9
- D. 6
Correct answer: C. 9
Two pointers on the sorted array: pairs with product ≥ 18 are (3,6), (3,9), (3,12), (4,6), (4,9), (4,12), (6,9), (6,12), (9,12) → 9. Using > 18 drops (3, 6) (8), counting the complement gives 6, and starting j at i adds 6·6, 9·9, 12·12 (12).
More Coding Interview Problems questions
- How many integers x with 1 <= x <= 64 have a binary representation (without leading zeros) that reads the same forwards and backwards?
- Problem: The suffix array of a string is its suffix start indices sorted by the suffix text. What is the value at position 2 (0-based) for…
- Problem: How many topological orders does the DAG with edges 0->2, 1->2, 2->3 on vertices 0..3 have? Run the brute-force code. python from…
- Problem: A row of 5 cells starts as [0, 0, 1, 0, 0]. Each step, every cell becomes the XOR of its two neighbours (cells outside the row…
- Problem: What is the exponent of the prime 3 in 100!? Use Legendre's formula, summing 100 // 3^k. Run the code. python print(sum(100 // 3…
- Problem: How many collinear triples of points does the 3 x 3 grid {0,1,2}^2 contain? Use the cross-product test below. python from…