Data Structures & AlgorithmsHard

How many index triples i < k < j in 2 4 6 3 9 5 satisfy A[i] + A[j] = 2·A[k] (the middle value is the arithmetic mean of the outer two)?

  1. A. 6
  2. B. 1
  3. C. 2
  4. D. 0

Correct answer: B. 1

Enumerate index triples in order with the middle index as k, and test the arithmetic-mean relation. Counting even-sum pairs, putting the middle value at the wrong end, or using a plain sum relation changes the count.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic