There are n workers, where n is odd. The efficiency of the i-th worker is given by efficiency[i].
Exactly one worker must be excluded. The remaining workers are paired such that every worker belongs to exactly one pair.
The cost of pairing two workers equals the absolute difference of their efficiencies.
Find the minimum possible total pairing cost after optimally choosing the excluded worker and forming the pairs.
int findMinCost(vector<int> efficiency);
efficiency[n]: efficiency rating of each worker.int: minimum possible total pairing cost.3 ≤ n ≤ 10^5n is odd1 ≤ efficiency[i] ≤ 10^95
4
8
1
2
16
5
Exclude the worker with efficiency 16.
The remaining efficiencies are:
[1, 2, 4, 8]
Pair them as:
(1, 2) → cost = 1(4, 8) → cost = 4Total cost = 1 + 4 = 5.
Flipkart • Pending
Flipkart • Pending
Flipkart • Pending
Texas • Pending
BNY • Pending