Class Solution
java.lang.Object
g2401_2500.s2491_divide_players_into_teams_of_equal_skill.Solution
2491 - Divide Players Into Teams of Equal Skill.<p>Medium</p>
<p>You are given a positive integer array <code>skill</code> of <strong>even</strong> length <code>n</code> where <code>skill[i]</code> denotes the skill of the <code>i<sup>th</sup></code> player. Divide the players into <code>n / 2</code> teams of size <code>2</code> such that the total skill of each team is <strong>equal</strong>.</p>
<p>The <strong>chemistry</strong> of a team is equal to the <strong>product</strong> of the skills of the players on that team.</p>
<p>Return <em>the sum of the <strong>chemistry</strong> of all the teams, or return</em> <code>-1</code> <em>if there is no way to divide the players into teams such that the total skill of each team is equal.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> skill = [3,2,5,1,3,4]</p>
<p><strong>Output:</strong> 22</p>
<p><strong>Explanation:</strong> Divide the players into the following teams: (1, 5), (2, 4), (3, 3), where each team has a total skill of 6. The sum of the chemistry of all the teams is: 1 * 5 + 2 * 4 + 3 * 3 = 5 + 8 + 9 = 22.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> skill = [3,4]</p>
<p><strong>Output:</strong> 12</p>
<p><strong>Explanation:</strong> The two players form a team with a total skill of 7. The chemistry of the team is 3 * 4 = 12.</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> skill = [1,1,2,3]</p>
<p><strong>Output:</strong> -1</p>
<p><strong>Explanation:</strong> There is no way to divide the players into teams such that the total skill of each team is equal.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>2 <= skill.length <= 10<sup>5</sup></code></li>
<li><code>skill.length</code> is even.</li>
<li><code>1 <= skill[i] <= 1000</code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
dividePlayers
public long dividePlayers(int[] skill)
-