[AlgoExpert] Tournament Winner

Tournament Winner

  • Time : O(n)
  • Space : O(team)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <vector>
using namespace std;

string tournamentWinner(vector<vector<string>> competitions,
vector<int> results) {
unordered_map<string, int> mp;
string res = "";
int ma = 0;
for(int i = 0; i < results.size(); i++) {
string winner = competitions[i][abs(results[i] - 1)];
if(ma < (mp[winner] += 3)) {
ma = mp[winner];
res = winner;
}
}
return res;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/05/10/PS/AlgoExpert/tournament-winner/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.