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?

  1. A. 8
  2. B. 11
  3. C. 4
  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

Exams that ask this topic