Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA
Sequence [5, 2, 9, 1, 7, 3]. Consider only index pairs i < j with j - i <= 2. What is the largest value of |a[i] - a[j]| over these pairs?
- A. 8
- B. 11
- C. 4
- D. 9
Correct answer: A. 8
The restriction j - i <= 2 is a sliding window of width 2, so only neighbours and near-neighbours need checking. The unrestricted maximum over all pairs can use far-apart indices, which the question excludes.
More Coding Interview Problems questions
- What is the length of the longest strictly increasing subsequence of [3, 1, 4, 1, 5, 9, 2, 6, 5, 3]? Use the patience-sorting method with…
- Sorted array [1, 2, 7, 8, 11, 15]. How many index triples i < j < k satisfy a[i] + a[j] + a[k] = 18?
- Four jobs have processing times [6, 3, 5, 2]. They run one at a time in some order, and job at position i (1-based) incurs cost i times…
- For the values [2, 5, 3, 8, 1, 6], how many values give remainder 1 or 2 when divided by 3 (counted once for each value)?
- Array [4, 4, 7, 1, 7, 2]. How many index pairs i < j have equal values a[i] = a[j]?
- Array [3, 7, 2, 9, 4]. How many contiguous subarrays sum to exactly 9?