Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: The array [1, 4, 3, 2] (with even length) is split into two-element pairs in any way, and the minimum of each pair is added up. What is the maximum possible total?

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

Correct answer: C. 4

Pairing sorted neighbours maximises the sum of mins, since each minimum is then as large as possible. Pairing the two largest together wastes their size.

More Coding Interview Problems questions

Exams that ask this topic