Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Sorted array b = [1, 2, 3, 4, 5, 7, 8, 9]. What is the largest product b[i] * b[j] over index pairs with j - i >= 3?
- A. 36
- B. 49
- C. 45
- D. 72
Correct answer: C. 45
Because the values are sorted, the largest product with an index gap of at least 3 comes from pairing the largest value with the largest value that is at least three positions to its left. Allowing gap 1 gives the unrestricted maximum, which is the trap.
More Coding Interview Problems questions
- Sorted array [1, 3, 4, 6, 8, 9, 11]. How many index triples i < j < k satisfy c[k] - c[i] <= 4?
- How many strings of length 5 over the alphabet {a, b, c} have no two adjacent characters equal?
- How many non-empty subsets of {1, 2, 3, 4, 5, 6} have an XOR of their elements that is at least 4?
- How many subsets (including the empty subset) of the values [2, 3, 5, 7, 11, 13, 4, 6] have a sum between 10 and 20 inclusive?
- The values [7, 4, 9, 2, 6, 5] are distributed among two groups (each value goes to exactly one group, any group may be empty). What is the…
- Closed intervals [1,3], [2,6], [3,5], [4,8], [7,9], [9,11], [10,12]. Two intervals conflict if they share any point, endpoints included…