Data Structures & AlgorithmsHard

How many contiguous windows of length exactly 2 in 4 7 2 9 3 5 11 8 have BOTH values prime?

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

Correct answer: A. 3

Each length-2 window needs both its values prime, and 1 is not prime so it never qualifies. Using OR instead of AND, adding a distinctness rule that is not asked, or comparing positions two apart each change the answer.

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

Exams that ask this topic