Data Structures & AlgorithmsHard

How many contiguous subarrays of length exactly 4 in 9 7 8 5 4 2 3 1 are STRICTLY decreasing?

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

Correct answer: D. 1

A strictly decreasing window needs each of its three adjacent comparisons to be strict, which is checked directly. Allowing equal neighbours, counting adjacent pairs, or comparing only the ends answers a different question.

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

Exams that ask this topic