Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT

Count the pairs of positions (i < j) in [3, 4, 7, 2, 9, 6] such that a[i] + a[j] is odd and i + j is even.

  1. A. 2
  2. B. -1
  3. C. 9
  4. D. 0

Correct answer: D. 0

Classify each position by the parity of its index and of its value, then count pairs whose index parities give an even sum and whose value parities differ. Ignoring the index condition counts a different set of pairs.

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

Exams that ask this topic