Problem · Array

Total Efficiency

Learn this problem
MediumIBM logoIBMFULLTIMEOA
See IBM hiring insights

Problem statement

Given an even-length array skill, assign every participant to a two-person team.

A grouping is valid only when every team has the same total skill. The efficiency of a team is the product of its two skill values.

Return the sum of all team efficiencies. If no valid grouping exists, return -1.

Function

getTotalEfficiency(skill: int[]) → long

Examples

Example 1

skill = [1, 2, 3, 2]return = 7

Pair the values as [1, 3] and [2, 2]. Both teams have total skill 4. Their efficiencies are 3 and 4, so the result is 7.

Constraints

  • 2 ≤ skill.length ≤ 2 × 10^5
  • skill.length is even.
  • 1 ≤ skill[i] ≤ 10^9

More IBM problems

drafts saved locally
public long getTotalEfficiency(int[] skill) {
    // Write your code here
}
skill[1, 2, 3, 2]
expected7
checking account