Data Structures & AlgorithmsModerate

How many contiguous windows of length exactly 3 in 4 1 2 3 9 8 6 7 are strictly monotone (increasing or decreasing) AND contain the global maximum 9?

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

Correct answer: B. 2

Both conditions apply to the same window: strict monotonicity and containment of the maximum. Dropping either, or restricting to increasing windows only, changes the total.

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

Exams that ask this topic