Data Structures & AlgorithmsModerateTCS NQT · Infosys

Array [3, 7, 2, 9, 4]. How many contiguous subarrays sum to exactly 9?

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

Correct answer: C. 2

Accumulate from each start index; the matches are [9] and [7, 2], so the answer is 2. Counting only elements equal to 9 misses the window [7, 2].

More Coding Interview Problems questions

Exams that ask this topic