Data Structures & AlgorithmsHard

How many contiguous subarrays of length exactly 2 in 2 4 7 9 1 3 6 8 consist of two values with the SAME parity?

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

Correct answer: D. 5

Parity equality is checked for each adjacent pair of positions; a length-2 window contains exactly one such pair. Comparing the opposite parity, testing equal values, or comparing positions two apart each count something else.

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

Exams that ask this topic