Data Structures & AlgorithmsModerateCAT · TCS NQT

Problem: How many unordered pairs {x, y} with x ≠ y from the set {1, 2, 3, 4, 5} have x + y even?

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

Correct answer: D. 4

Two numbers have an even sum exactly when they share parity. The odd numbers 1, 3, 5 give three pairs and the even numbers 2, 4 give one pair, totalling four.

More Coding Interview Problems questions

Exams that ask this topic