Data Structures & AlgorithmsModerate

From the array 1 5 3 3 3 7 2 4 6, choose the largest number of PAIRS of positions so that every position is used in at most one pair and each pair sums to 6. What is that maximum number of pairs?

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

Correct answer: B. 3

Pairs must be disjoint, so the problem is maximum matching in a graph where equal-complement values connect. Counting all qualifying index pairs over-counts overlapping ones, and the half-length bound ignores which values actually match.

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

Exams that ask this topic