Data Structures & AlgorithmsVery hard

How many contiguous subarrays of 5 1 9 4 8 3 7 have (maximum − minimum) at least 3?

  1. A. 15
  2. B. 7
  3. C. 22
  4. D. 21

Correct answer: D. 21

The complement of the spread condition is the set with max − min below 3, so the target count is total minus that. Checking strict inequality or restricting the length changes the set, and the complement is the wrong side.

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

Exams that ask this topic