Data Structures & AlgorithmsHard

How many contiguous windows of length 3 in 1 3 5 6 8 10 11 12 form an arithmetic progression (the two consecutive differences are equal)?

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

Correct answer: D. 3

A length-3 window is an arithmetic progression when the two neighbouring differences match. Checking only the first difference, or counting windows whose differences are unequal, gives the wrong set.

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

Exams that ask this topic