Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

How many distinct sums appear over all non-empty contiguous subarrays of [2, 1, 3, 1]?

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

Correct answer: D. 7

Put every subarray sum into a set and count it; the positional count of 10 subarrays is not the same as the number of distinct values.

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

Exams that ask this topic