Data Structures & AlgorithmsHard

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

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

Correct answer: A. 5

The prime test is applied to the sum and the even-length test to the block size; both must hold together. Dropping the length rule, flipping it, or swapping the prime test for parity each change the count.

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

Exams that ask this topic