FastPrepObtain Maximum Score Using Minimum Swaps
Problems/Obtain Maximum Score Using Minimum Swaps

Obtain Maximum Score Using Minimum Swaps

Infosys logoInfosys● MediumOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Updated 07-18-2026: The source omits the positive-value condition required by its intended maximum-product pairing rule, and its second displayed swap result does not follow from the first. FastPrep makes the positive, distinct-value domain explicit and corrects the intermediate array while preserving the source answer.

You are given an array arr containing an even number of distinct positive integers. You may swap any two positions in one operation.

After rearrangement, the score is the product of the sums of adjacent pairs:

(arr[0] + arr[1]) * (arr[2] + arr[3]) * ... * (arr[n - 2] + arr[n - 1]).

Return the minimum number of swaps needed to obtain the maximum possible score.

Function

minimumSwapsForMaximumScore(arr: int[]) → int

Examples

Example 1

arr = [4, 1, 2, 9, 3, 6]return = 2

For positive values, the maximum score is obtained by pairing the smallest value with the largest, the second-smallest with the second-largest, and so on. Here the required pairs are (1, 9), (2, 6), and (3, 4).

  1. Swap 4 and 9 to obtain [9, 1, 2, 4, 3, 6].
  2. Swap 4 and 6 to obtain [9, 1, 2, 6, 3, 4].

The adjacent pair sums are then 10, 8, and 7. The maximum score is reached in the minimum possible 2 swaps.

Constraints

  • arr.length is positive and even.
  • Every value in arr is a positive integer.
  • All values in arr are distinct.

More Infosys interview questions

  • At Most K Jumps with Quadratic Transition CostOA · Seen Nov 2026
  • Hiking Club Fastest PaceOA · Seen Nov 2026
  • Lowest Common Ancestor with a Changing RootOA · Seen Nov 2026
  • Minimum Coins for a TargetONSITE INTERVIEW · Seen Nov 2026
  • Minimum Leaf Path Sum over All RootsOA · Seen Nov 2026
  • Split Array to Minimize the Largest SumOA · Seen Nov 2026
  • Cherry PickupOA · Seen Nov 2026
  • Delete Duplicate Employee RecordsONSITE INTERVIEW · Seen Nov 2026
  • Find Duplicate Employee RecordsONSITE INTERVIEW · Seen Nov 2026
  • Lexicographically Smallest Grid Path with One Letter ChangeOA · Seen Nov 2026

Similar questions at other companies

  • Find Minimum TimeAlphaSense · OA
  • Find Minimum TimeBlackRock · OABlackRock interview questions
  • Maximum Easy Tasks After RearrangingIBM · OAIBM interview questions
  • Minimum Cost K-Capable ModelsMicrosoft · OAMicrosoft interview questions
  • Minimum Cost of Every K-Capable Model SetTikTok · OATikTok interview questions
  • Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
  • Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
  • Minimum Distinct Prefix CostGoldman Sachs · OAGoldman Sachs interview questions
  • Maximize Minimum Deployment DifficultyJP Morgan Chase · OAJP Morgan Chase interview questions
  • Latest Arrival to Catch a BusAutodesk · OAAutodesk interview questions
All Infosys interview questionsSee Infosys hiring insights
Saved
class Solution {
    public int minimumSwapsForMaximumScore(int[] arr) {
        // write your code here
    }

}
Checking account…