Data Structures & AlgorithmsModerateTCS NQT · Codeforces Div2 B

What is the length of the longest contiguous subarray of [4, 7, 2, 9, 6, 3, 8, 10, 5] in which the parity of consecutive elements alternates (even, odd, even, ... or odd, even, odd, ...)?

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

Correct answer: A. 8

Scan once: extend the current run when the parity changes, and restart otherwise. Counting parity changes over the whole array is not the same as the longest contiguous run.

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

Exams that ask this topic