You are given a positive integer array `skill` of even length `n`, where `skill[i]` is the skill of the `i`th player. Divide the players into `n / 2` teams of two so that every team has the same total skill. The **chemistry** of a team is the product of its two skills. Return the sum of the chemistry of all teams, or `-1` if the players cannot be divided so that every team has equal total skill.
You are given a positive integer array skill of even length n, where skill[i] is the skill of the ith player. Divide the players into n / 2 teams of two so that every team has the same total skill. The chemistry of a team is the product of its two skills. Return the sum of the chemistry of all teams, or -1 if the players cannot be divided so that every team has equal total skill.
Example 1:
Input: {"skill":[3,2,5,1,3,4]}
Output: 22
Constraints:
2≤skill.length≤105
skill.length is even.
1≤skill[i]≤1000
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"skill":[3,2,5,1,3,4]}
6 players must form 3 teams of two with the same total. Sort first, so the weakest player can be paired with the strongest.