We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents def463e + d7f7795 commit 1ceb243Copy full SHA for 1ceb243
2491. Divide Players Into Teams of Equal Skill
@@ -0,0 +1,26 @@
1
+class Solution {
2
+public:
3
+ long long dividePlayers(vector<int>& skill) {
4
+
5
+ long long n = skill.size();
6
+ sort(skill.begin() , skill.end());
7
+ vector<long long>a;
8
+ long long start = 0,end = n-1;
9
+ long long sum = skill[0] + skill[n-1];
10
+ long long k = 0;
11
12
+ while(start<=end){
13
+ if((skill[start] + skill[end])!= sum) return -1;
14
+ a.push_back(skill[start]);
15
+ a.push_back(skill[end]);
16
+ start++;end--;k++;
17
+ }
18
+ k=0;
19
+ long long ans = 0;
20
+ for(long long i = 0 ; i < a.size() ; i+=2){
21
+ ans+=a[i]*a[i+1];
22
+ k++;
23
24
+ return ans;
25
26
+};
0 commit comments