1366. Rank Teams by Votes
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 59% Topics: Array, Hash Table, String, Sorting, Counting
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(m * (n + mlogm)), n is the number of votes
# , m is the length of vote
# Space: O(m^2)
class Solution(object):
def rankTeams(self, votes):
"""
:type votes: List[str]
:rtype: str
"""
count = {v: [0]*len(votes[0]) + [v] for v in votes[0]}
for vote in votes:
for i, v in enumerate(vote):
count[v][i] -= 1
return "".join(sorted(votes[0], key=count.__getitem__))
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions