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

Solution Day-19 q1: Find Players With Zero or One Losses #423

Merged
merged 7 commits into from
Jan 22, 2024
30 changes: 30 additions & 0 deletions Day-19/q1 Find Players With Zero or One Losses/avanimathur--C.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <bits/stdc++.h>
using namespace std;

class Solution {
public:
vector<vector<int>> findPlayers(vector<vector<int>>& matches) {

unordered_map<int, int> lossesCount;

for (const auto& match : matches) {
lossesCount[match[1]]++;
}

vector<int> zeroLosses;
vector<int> oneLoss;

for (const auto& entry : lossesCount) {
if (entry.second == 0) {
zeroLosses.push_back(entry.first);
} else if (entry.second == 1) {
oneLoss.push_back(entry.first);
}
}

sort(zeroLosses.begin(), zeroLosses.end());
sort(oneLoss.begin(), oneLoss.end());

return {zeroLosses, oneLoss};
}
};