Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

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

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

Correct answer: B. 4

Subtract the count of sums at most 5 from the count of sums at most 6 is one approach; here the subarray sums are checked directly and the endpoints 4 and 6 are both included.

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

Exams that ask this topic