Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA

Sorted array [1, 3, 4, 6, 8, 9, 11]. How many index triples i < j < k satisfy c[k] - c[i] <= 4?

  1. A. 7
  2. B. 4
  3. C. 6
  4. D. 5

Correct answer: D. 5

Fix the left index i and move the right pointer while the spread stays within 4; each valid right end contributes the number of values strictly between i and it. Strict bounds drop triples whose spread is exactly 4.

More Coding Interview Problems questions

Exams that ask this topic