Data Structures & AlgorithmsVery hard

How many contiguous windows of length exactly 3 in 4 1 7 3 9 5 2 have their MIDDLE element equal to the median of the window?

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

Correct answer: B. 1

Sort each window of three values and check whether its middle position holds the original middle element. Testing for maximum or minimum, or the first element, measures different positions.

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

Exams that ask this topic