2491. Divide Players Into Teams of Equal Skill Medium

@problem@discussion



1/**
2 * [2491] Divide Players Into Teams of Equal Skill
3 *
4 * You are given a positive integer array skill of even length n where skill[i] denotes the skill of the i^th player. Divide the players into n / 2 teams of size 2 such that the total skill of each team is equal.
5 * The chemistry of a team is equal to the product of the skills of the players on that team.
6 * Return the sum of the chemistry of all the teams, or return -1 if there is no way to divide the players into teams such that the total skill of each team is equal.
7 *  
8 * <strong class="example">Example 1:
9 * 
10 * Input: skill = [3,2,5,1,3,4]
11 * Output: 22
12 * Explanation: 
13 * Divide the players into the following teams: (1, 5), (2, 4), (3, 3), where each team has a total skill of 6.
14 * The sum of the chemistry of all the teams is: 1 * 5 + 2 * 4 + 3 * 3 = 5 + 8 + 9 = 22.
15 * 
16 * <strong class="example">Example 2:
17 * 
18 * Input: skill = [3,4]
19 * Output: 12
20 * Explanation: 
21 * The two players form a team with a total skill of 7.
22 * The chemistry of the team is 3 * 4 = 12.
23 * 
24 * <strong class="example">Example 3:
25 * 
26 * Input: skill = [1,1,2,3]
27 * Output: -1
28 * Explanation: 
29 * There is no way to divide the players into teams such that the total skill of each team is equal.
30 * 
31 *  
32 * Constraints:
33 * 
34 * 	2 <= skill.length <= 10^5
35 * 	skill.length is even.
36 * 	1 <= skill[i] <= 1000
37 * 
38 */
39pub struct Solution {}
40
41// problem: https://leetcode.com/problems/divide-players-into-teams-of-equal-skill/
42// discuss: https://leetcode.com/problems/divide-players-into-teams-of-equal-skill/discuss/?currentPage=1&orderBy=most_votes&query=
43
44// submission codes start here
45
46impl Solution {
47    pub fn divide_players(skill: Vec<i32>) -> i64 {
48        
49    }
50}
51
52// submission codes end
53
54#[cfg(test)]
55mod tests {
56    use super::*;
57
58    #[test]
59    fn test_2491() {
60    }
61}
62


Back
© 2025 bowen.ge All Rights Reserved.