3238. Find the Number of Winning Players
Read the full problem statement on LeetCode.
Difficulty: easy Acceptance: 60% Topics: Array, Hash Table, Counting
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(p), p = len(pick)
# Space: O(min(n * c, p)), c = max(y)
import collections
# freq table
class Solution(object):
def winningPlayerCount(self, n, pick):
"""
:type n: int
:type pick: List[List[int]]
:rtype: int
"""
cnts = collections.defaultdict(lambda: collections.defaultdict(int))
for x, y in pick:
cnts[x][y] += 1
return sum(i < max(cnt.itervalues()) for i, cnt in cnts.iteritems())
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions