Data Structures & AlgorithmsVery hard

How many contiguous windows of length exactly 4 in 2 5 1 0 3 4 2 6 have a sum strictly less than 10?

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

Correct answer: B. 4

A fixed-size window slides one step at a time: add the entering value and subtract the leaving one to update the sum. Using ≤ instead of <, a window of the wrong length, or all subarrays changes the count.

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

Exams that ask this topic