Obtain Maximum Score Using Minimum Swaps

This Infosys interviews coding interview problem asks: Given an even-length array of distinct integers, you may swap any two elements. The score is the product of sums of adjacent pairs after rearrangement ((A1+A2)...(A[N-1]+A[N])). Find the minimum number of swaps needed to achieve the arrangement with maximum score. A practical interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: