Data Structures & AlgorithmsVery hard

How many index pairs i < j in 2 7 4 9 6 3 8 have an ODD sum A[i] + A[j] while also satisfying A[i] < A[j]?

  1. A. 12
  2. B. 13
  3. C. 7
  4. D. 6

Correct answer: D. 6

An odd sum needs one odd and one even value, and the index order also has to match the value order. Dropping either test, or reversing the comparison, changes the count.

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

Exams that ask this topic