Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

How many distinct sums are obtained by contiguous non-empty subarrays of [1, -1, 2, -2]?

  1. A. 6
  2. B. 5
  3. C. 7
  4. D. 8

Correct answer: B. 5

Enumerate all ten subarray sums and deduplicate them; repeated sums such as 0 and -1 count once. Counting subarrays (ten) instead gives a larger number.

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

Exams that ask this topic