Leetcode 1483 Solution
This article provides solution to leetcode question 1483 (rank-teams-by-votes)
Access this page by simply typing in "lcs 1483" in your browser address bar if you have bunnylol configured.
Leetcode Question Link
https://leetcode.com/problems/rank-teams-by-votes
Solution
class Solution:
def rankTeams(self, votes: List[str]) -> str:
score_len = len(votes[0])
scores = {}
for vote in votes:
for i, ch in enumerate(vote):
if ch not in scores:
scores[ch] = [0] * score_len + [-ord(ch)]
scores[ch][i] += 1
char_score_pairs = sorted([
(ch_scores, ch) for ch, ch_scores in scores.items()
], reverse=True)
return "".join([
ch for _, ch in char_score_pairs
])