Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

Two arrays a = [1, 3, 5] and b = [2, 4, 6] are given. You may reorder b arbitrarily and pair a[i] with the i-th element of the reordered b. What is the smallest possible value of the sum of products?

  1. A. 44
  2. B. 30
  3. C. 28
  4. D. 108

Correct answer: C. 28

By the rearrangement inequality the minimum comes from pairing the largest with the smallest, which here gives 1*6 + 3*4 + 5*2 = 28. Pairing in sorted order gives the maximum 44.

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

Exams that ask this topic