Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create 2491. Divide Players Into Teams of Equal Skill #604

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions 2491. Divide Players Into Teams of Equal Skill
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Solution {
public:
long long dividePlayers(vector<int>& skill) {

long long n = skill.size();
sort(skill.begin() , skill.end());
vector<long long>a;
long long start = 0,end = n-1;
long long sum = skill[0] + skill[n-1];
long long k = 0;

while(start<=end){
if((skill[start] + skill[end])!= sum) return -1;
a.push_back(skill[start]);
a.push_back(skill[end]);
start++;end--;k++;
}
k=0;
long long ans = 0;
for(long long i = 0 ; i < a.size() ; i+=2){
ans+=a[i]*a[i+1];
k++;
}
return ans;
}
};
Loading