Data Structures & AlgorithmsHardGATE CS · TCS NQT

Sum the lengths of all contiguous subarrays of [1, 2, 3, 4] whose element sum is even.

  1. A. 10
  2. B. 9
  3. C. 7
  4. D. 20

Correct answer: B. 9

Enumerate subarrays and add their lengths for those with even sums. Counting subarrays instead of summing lengths is a different quantity.

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

Exams that ask this topic