Data Structures & AlgorithmsVery hardTCS NQT · Accenture

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

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

Correct answer: A. 5

List the six subarray sums: 1, 2, 3, 3, 5, 6. Counting subarrays gives 6, but the question asks for distinct sums.

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

Exams that ask this topic