Data Structures & AlgorithmsModerate

How many contiguous subarrays of 3 2 5 4 7 6 1 8 have a PRIME length and an EVEN sum?

  1. A. 19
  2. B. 16
  3. C. 6
  4. D. 13

Correct answer: C. 6

Length 1 is not prime, so singletons are excluded even though they test the sum; the prime length and even sum must hold together. Dropping either test, or flipping the parity, changes the count.

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

Exams that ask this topic