Data Structures & AlgorithmsHard

How many contiguous windows of length exactly 3 in 1 4 7 2 5 8 3 6 have their MIDDLE element equal to the average of the first and last elements?

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

Correct answer: C. 2

The middle equals the average exactly when twice the middle equals the sum of the outer values, which avoids division. Writing the sum on the wrong side, dropping the equality, or testing a peak instead changes the count.

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

Exams that ask this topic