Skip to content

Commit

Permalink
Merge pull request #131 from niharikah005/Leetcode-3238
Browse files Browse the repository at this point in the history
Added solution to Leetcode 3238
  • Loading branch information
abhisek247767 authored Oct 25, 2024
2 parents 39930bd + 147e6b3 commit 24c8ed1
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions python/number-of-winning-players.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Leetcode 3238 - Number of Winning Players

'''
Problem:
You are given an integer n representing the number of players in a game and a 2D array pick where pick[i] = [xi, yi] represents that the player xi picked a ball of color yi.
Player i wins the game if they pick strictly more than i balls of the same color. In other words,
Player 0 wins if they pick any ball.
Player 1 wins if they pick at least two balls of the same color.
...
Player i wins if they pick at leasti + 1 balls of the same color.
Return the number of players who win the game.
Note that multiple players can win the game.'''

class Solution:
def winningPlayerCount(self, n: int, pick) -> int:
r = 0
cs = {}
rs = [0]*n
for i,k in pick:
if i not in cs:
cs[i]={}
if k not in cs[i]:
cs[i][k]=0
cs[i][k]+=1
if cs[i][k]>i:
rs[i]=1
return sum(rs)

0 comments on commit 24c8ed1

Please sign in to comment.