This is a verified interview question from Ui-path. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Efficient Workers - UI Path Online Assessment IIT Roorkee" covers key patterns like Arrays.
"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. ### Function Signature ```cpp int findMinCost(vector<int> efficiency); ``` ### Parameters * `efficiency[n]`: efficiency rating of each worker. ### Returns * `int`: minimum possible total pairing cost. ### Constraints * `3 ≤ n ≤ 10^5` * `n` is odd * `1 ≤ efficiency[i] ≤ 10^9` ### Sample Input 0 ``` 5 4 8 1 2 16 ``` ### Sample Output 0 ``` 5 ``` ### Explanation Exclude the worker with efficiency `16`. The remaining efficiencies are: ``` [1, 2, 4, 8] ``` Pair them as: * `(1, 2)` → cost = 1 * `(4, 8)` → cost = 4 Total cost = `1 + 4 = 5`."
Join thousands of developers practicing for Ui-path.