Data Structures & AlgorithmsModerate

How many subsequences of EXACTLY three elements of 1 4 2 5 7 9 6 (position subsets read in order) form an arithmetic progression (the middle value is the mean of the other two)?

  1. A. 4
  2. B. 1
  3. C. 13
  4. D. 5

Correct answer: A. 4

Three values in order form an arithmetic progression exactly when the outer two sum to twice the middle. Checking the wrong position for the middle, testing divisibility by 3, or a plain sum relation each count different triples.

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

Exams that ask this topic