Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

How many contiguous subarrays of [2, 1, 3, 4, 2] have a sum in the inclusive range [5, 7]?

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

Correct answer: C. 3

For positive values, the count of subarrays with sum at most R minus the count with sum at most L - 1 gives the answer using two sliding windows. The inclusive ends matter.

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

Exams that ask this topic